diff --git a/Common/Dtos/Conversation/ADD_ConversationDto.cs b/Common/Dtos/Conversation/ADD_ConversationDto.cs index a7391e1..9f80343 100644 --- a/Common/Dtos/Conversation/ADD_ConversationDto.cs +++ b/Common/Dtos/Conversation/ADD_ConversationDto.cs @@ -7,6 +7,5 @@ namespace Common.Dtos.Conversation public string Question { get; set; } public int? GroupID { get; set; } public int CompanyID { get; set; } - public int? ExperID { get; set; } } } diff --git a/Hushian.Application/Contracts/IconversationAssistant.cs b/Hushian.Application/Contracts/IconversationAssistant.cs new file mode 100644 index 0000000..4406816 --- /dev/null +++ b/Hushian.Application/Contracts/IconversationAssistant.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Application.Contracts +{ + interface IconversationAssistant + { + } +} diff --git a/Hushian.Application/Services/AuthService.cs b/Hushian.Application/Services/AuthService.cs index ccf32af..573c516 100644 --- a/Hushian.Application/Services/AuthService.cs +++ b/Hushian.Application/Services/AuthService.cs @@ -27,7 +27,11 @@ namespace Hushian.Application.Services private readonly IGenericRepository _UserRepository; private readonly IGenericRepository _ExperRepository; private readonly VerificationService _verificationService; - public AuthService(IOptions jwtSettings, IGenericRepository companyRepository, IGenericRepository userRepository, IGenericRepository experRepository, VerificationService verificationService) + public AuthService(IOptions jwtSettings + , IGenericRepository companyRepository + , IGenericRepository userRepository + , IGenericRepository experRepository + , VerificationService verificationService) { _jwtSettings = jwtSettings.Value; _CompanyRepository = companyRepository; @@ -119,8 +123,6 @@ namespace Hushian.Application.Services public async Task GenerateToken(string UserName, int userId) { - - var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub,UserName), diff --git a/Hushian.Application/Services/CompanyService.cs b/Hushian.Application/Services/CompanyService.cs index cf4f7f5..19b1d86 100644 --- a/Hushian.Application/Services/CompanyService.cs +++ b/Hushian.Application/Services/CompanyService.cs @@ -22,6 +22,13 @@ namespace Hushian.Application.Services private readonly VerificationService _VerificationService; private readonly IMapper _mapper; + public CompanyService(IGenericRepository companyRepository, VerificationService verificationService, IMapper mapper) + { + _CompanyRepository = companyRepository; + _VerificationService = verificationService; + _mapper = mapper; + } + public async Task> RegisterCompany(RegisterCompanyDto dto) { ResponseBase Response = new(); @@ -197,6 +204,8 @@ namespace Hushian.Application.Services } public async Task AnyCompany(int CompanyID) =>await _CompanyRepository.Get().AnyAsync(a=>a.ID==CompanyID); + public async Task AllowBot(int CompanyID) + => await _CompanyRepository.Get().AnyAsync(a => a.ID == CompanyID && a.allowBot); private async Task Verifi(string Mobile) => await _VerificationService.GenerateCodeByPhoneNumberConfirmed(Mobile); } diff --git a/Hushian.Application/Services/ConversationService.cs b/Hushian.Application/Services/ConversationService.cs index 9e83333..aafdbfc 100644 --- a/Hushian.Application/Services/ConversationService.cs +++ b/Hushian.Application/Services/ConversationService.cs @@ -18,11 +18,25 @@ namespace Hushian.Application.Services { private readonly IGenericRepository _ConversationRepository; private readonly IGenericRepository _ConversationResponseRepository; - private readonly IMapper _mapper; private readonly CompanyService _companyService; private readonly UserService _userService; private readonly GroupService _groupService; private readonly ExperService _experService; + + public ConversationService( + IGenericRepository conversationRepository + , IGenericRepository conversationResponseRepository + , CompanyService companyService, UserService userService, GroupService groupService + , ExperService experService) + { + _ConversationRepository = conversationRepository; + _ConversationResponseRepository = conversationResponseRepository; + _companyService = companyService; + _userService = userService; + _groupService = groupService; + _experService = experService; + } + public async Task> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE) { var Response = new ResponseBase(); @@ -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 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; + } } } diff --git a/Hushian.Application/Services/ExperService.cs b/Hushian.Application/Services/ExperService.cs index 08e1c20..a0b929b 100644 --- a/Hushian.Application/Services/ExperService.cs +++ b/Hushian.Application/Services/ExperService.cs @@ -16,10 +16,17 @@ namespace Hushian.Application.Services { public class ExperService { - private readonly IGenericRepository _CompanyRepository; private readonly IGenericRepository _ExperRepository; private readonly VerificationService _VerificationService; private readonly IMapper _mapper; + + public ExperService(IGenericRepository experRepository, VerificationService verificationService, IMapper mapper) + { + _ExperRepository = experRepository; + _VerificationService = verificationService; + _mapper = mapper; + } + public async Task> ADDExper(ADD_ExperDto dto, int CompanyID) { var Response = new ResponseBase(); diff --git a/Hushian.Application/Services/GroupService.cs b/Hushian.Application/Services/GroupService.cs index 540b6fa..964b1d6 100644 --- a/Hushian.Application/Services/GroupService.cs +++ b/Hushian.Application/Services/GroupService.cs @@ -20,6 +20,17 @@ namespace Hushian.Application.Services private readonly IGenericRepository _EGRepository; private readonly IMapper _mapper; private readonly ExperService _experService; + + public GroupService(IGenericRepository groupRepository + , IGenericRepository eGRepository + , IMapper mapper, ExperService experService) + { + _GroupRepository = groupRepository; + _EGRepository = eGRepository; + _mapper = mapper; + _experService = experService; + } + public async Task> NewGroup(ADD_GroupDto model, int CompanyID) { ResponseBase Response = new(); diff --git a/Hushian.Application/Services/VerificationService.cs b/Hushian.Application/Services/VerificationService.cs index a2d1b03..1c812f1 100644 --- a/Hushian.Application/Services/VerificationService.cs +++ b/Hushian.Application/Services/VerificationService.cs @@ -27,7 +27,12 @@ namespace Hushian.Application.Services private readonly IGenericRepository _UserRepository; private readonly AuthService _authService; - public VerificationService(IGenericRepository verificationCodeRepository, IMessageSender messageSender, IGenericRepository userRepository, AuthService authService, IGenericRepository companyRepository, IGenericRepository experRepository) + public VerificationService(IGenericRepository verificationCodeRepository + , IMessageSender messageSender + , IGenericRepository userRepository + , AuthService authService + , IGenericRepository companyRepository + , IGenericRepository experRepository) { _VerificationCodeRepository = verificationCodeRepository; _messageSender = messageSender;