...
This commit is contained in:
@@ -18,11 +18,25 @@ namespace Hushian.Application.Services
|
||||
{
|
||||
private readonly IGenericRepository<Conversation> _ConversationRepository;
|
||||
private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly CompanyService _companyService;
|
||||
private readonly UserService _userService;
|
||||
private readonly GroupService _groupService;
|
||||
private readonly ExperService _experService;
|
||||
|
||||
public ConversationService(
|
||||
IGenericRepository<Conversation> conversationRepository
|
||||
, IGenericRepository<ConversationResponse> conversationResponseRepository
|
||||
, CompanyService companyService, UserService userService, GroupService groupService
|
||||
, ExperService experService)
|
||||
{
|
||||
_ConversationRepository = conversationRepository;
|
||||
_ConversationResponseRepository = conversationResponseRepository;
|
||||
_companyService = companyService;
|
||||
_userService = userService;
|
||||
_groupService = groupService;
|
||||
_experService = experService;
|
||||
}
|
||||
|
||||
public async Task<ResponseBase<int>> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
|
||||
{
|
||||
var Response = new ResponseBase<int>();
|
||||
@@ -30,9 +44,18 @@ namespace Hushian.Application.Services
|
||||
{
|
||||
if (await _userService.AnyUser(dto.UserID))
|
||||
{
|
||||
if (type == ConversationType.Bot)
|
||||
{
|
||||
if (!await _companyService.AllowBot(dto.CompanyID))
|
||||
{
|
||||
Response.Errors.Add("دستیار گفتگو هوشمند برای این شرکت در دسترس نمی باشد");
|
||||
return Response;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dto.GroupID.HasValue || (dto.GroupID.HasValue
|
||||
&& await _groupService.AnyGroup(dto.GroupID.Value)
|
||||
&& await _groupService.CHeckGroupMemberCompany(dto.GroupID.Value, dto.CompanyID)))
|
||||
&& await _groupService.AnyGroup(dto.GroupID.Value)
|
||||
&& await _groupService.CHeckGroupMemberCompany(dto.GroupID.Value, dto.CompanyID)))
|
||||
{
|
||||
Conversation conversation = new Conversation()
|
||||
{
|
||||
@@ -46,6 +69,8 @@ namespace Hushian.Application.Services
|
||||
}
|
||||
else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
|
||||
|
||||
|
||||
|
||||
}
|
||||
else Response.Errors.Add("شناسه کاربر یافت نشد");
|
||||
|
||||
@@ -118,7 +143,7 @@ namespace Hushian.Application.Services
|
||||
=> await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.ConversationResponses.Any(a=>a.ExperID==ExperID) && w.Status==ConversationStatus.Finished)
|
||||
.Where(w => w.ConversationResponses.Any(a => a.ExperID == ExperID) && w.Status == ConversationStatus.Finished)
|
||||
.Select(s => new Read_ConversationDto()
|
||||
{
|
||||
ExperID = s.ConversationResponses.Last().ExperID,
|
||||
@@ -177,5 +202,19 @@ namespace Hushian.Application.Services
|
||||
UserFullName = s.User.FullName
|
||||
|
||||
}).ToListAsync();
|
||||
public async Task<bool> FinishConversation(int ConversationID)
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w => w.ID == ConversationID);
|
||||
|
||||
if (convModel != null && convModel.Status != ConversationStatus.Finished)
|
||||
{
|
||||
convModel.Status = ConversationStatus.Finished;
|
||||
return await _ConversationRepository.UPDATEBool(convModel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user