diff --git a/Common/Dtos/Conversation/ADD_ConversationDto.cs b/Common/Dtos/Conversation/ADD_ConversationDto.cs index 9865051..a7391e1 100644 --- a/Common/Dtos/Conversation/ADD_ConversationDto.cs +++ b/Common/Dtos/Conversation/ADD_ConversationDto.cs @@ -3,6 +3,7 @@ namespace Common.Dtos.Conversation { public class ADD_ConversationDto { + public int UserID { get; set; } public string Question { get; set; } public int? GroupID { get; set; } public int CompanyID { get; set; } diff --git a/Common/Dtos/Conversation/ADD_ConversationItemDto.cs b/Common/Dtos/Conversation/ADD_ConversationResponseDto.cs similarity index 71% rename from Common/Dtos/Conversation/ADD_ConversationItemDto.cs rename to Common/Dtos/Conversation/ADD_ConversationResponseDto.cs index 01a2189..d71217e 100644 --- a/Common/Dtos/Conversation/ADD_ConversationItemDto.cs +++ b/Common/Dtos/Conversation/ADD_ConversationResponseDto.cs @@ -1,9 +1,12 @@  +using Common.Enums; + namespace Common.Dtos.Conversation { - public class ADD_ConversationItemDto + public class ADD_ConversationResponseDto { public int ConversationID { get; set; } + public ConversationType Type { get; set; } public string Text { get; set; } public string? FileName { get; set; } public string? FileType { get; set; } diff --git a/Common/Enums/ConversationType.cs b/Common/Enums/ConversationType.cs index 04394a7..f507f54 100644 --- a/Common/Enums/ConversationType.cs +++ b/Common/Enums/ConversationType.cs @@ -8,6 +8,6 @@ namespace Common.Enums { public enum ConversationType { - EU = 1, UE = 2 + EU = 1, UE = 2,Bot=3 } } diff --git a/Hushian.Application/Services/CompanyService.cs b/Hushian.Application/Services/CompanyService.cs index a484eae..cf4f7f5 100644 --- a/Hushian.Application/Services/CompanyService.cs +++ b/Hushian.Application/Services/CompanyService.cs @@ -195,6 +195,8 @@ namespace Hushian.Application.Services return Response; } + public async Task AnyCompany(int CompanyID) + =>await _CompanyRepository.Get().AnyAsync(a=>a.ID==CompanyID); private async Task Verifi(string Mobile) => await _VerificationService.GenerateCodeByPhoneNumberConfirmed(Mobile); } diff --git a/Hushian.Application/Services/ConversationService.cs b/Hushian.Application/Services/ConversationService.cs new file mode 100644 index 0000000..fa9161a --- /dev/null +++ b/Hushian.Application/Services/ConversationService.cs @@ -0,0 +1,105 @@ +using AutoMapper; +using Common.Dtos.Conversation; +using Common.Enums; +using Hushian.Application.Contracts.Persistence; +using Hushian.Application.Models; +using Hushian.Domain.Entites; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Application.Services +{ + public class ConversationService + { + 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 async Task> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE) + { + var Response = new ResponseBase(); + if (await _companyService.AnyCompany(dto.CompanyID)) + { + if (await _userService.AnyUser(dto.UserID)) + { + if (!dto.GroupID.HasValue || (dto.GroupID.HasValue + && await _groupService.AnyGroup(dto.GroupID.Value) + && await _groupService.CHeckGroupMemberCompany(dto.GroupID.Value, dto.CompanyID))) + { + Conversation conversation = new Conversation() + { + CompanyID = dto.CompanyID, + UserID = dto.UserID, + GroupID = dto.GroupID, + ConversationResponses = new List() { new() { Text = dto.Question, Type = type } } + }; + Response.Value = (await _ConversationRepository.ADD(conversation)).ID; + Response.Success = Response.Value > 0; + } + else Response.Errors.Add("شناسه گروه صحیح نمی باشد"); + + } + else Response.Errors.Add("شناسه کاربر یافت نشد"); + + } + else Response.Errors.Add("شناسه شرکت یافت نشد"); + + + return Response; + } + public async Task> NewConversationResponse(ADD_ConversationResponseDto dto, int? ExperID) + { + var Response = new ResponseBase(); + if (dto.Type == ConversationType.EU && !ExperID.HasValue) + { + Response.Errors.Add("کارشناس گفتگو را مشخص گنید"); + } + else + { + var convModel = await _ConversationRepository.Get() + .Include(inc => inc.ConversationResponses) + .FirstOrDefaultAsync(w => w.ID == dto.ConversationID); + + if (convModel != null) + { + if (ExperID.HasValue && !await _experService.CheckExperInCompany(convModel.CompanyID, ExperID.Value)) + { + Response.Errors.Add("کارشناس گفتگو صحیح نمی باشد"); + return Response; + } + ConversationResponse response = new ConversationResponse() + { + ConversationID = convModel.ID, + Text = dto.Text, + Type = dto.Type, + ExperID = ExperID, + FileContent = dto.FileContent, + FileType = dto.FileType, + FileName = dto.FileName + }; + Response.Value = (await _ConversationResponseRepository.ADD(response)).ID; + Response.Success = Response.Value > 0; + } + else Response.Errors.Add("گفتگویی یافت نشد"); + } + + return Response; + } + public async Task> MyConversation(int CompanyID, string UserID) + { return new(); } + public async Task> MyConversationIsFinished(int CompanyID, string? ExperID = null) + { return new(); } + public async Task> MyConversationIsInProgress(int CompanyID, string ExperID) + { return new(); } + public async Task> ConversationAwaitingOurResponse(int CompanyID, string? ExperID = null) + { return new(); } + } +} diff --git a/Hushian.Application/Services/GroupService.cs b/Hushian.Application/Services/GroupService.cs index 6bcf6f0..540b6fa 100644 --- a/Hushian.Application/Services/GroupService.cs +++ b/Hushian.Application/Services/GroupService.cs @@ -110,11 +110,11 @@ namespace Hushian.Application.Services } return false; } - - public async Task CHeckGroupMemberCompany(int GroupID, int CompanyID) - { - return await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID); - } + public async Task AnyGroup(int GroupID) => + await _GroupRepository.Get().AnyAsync(a=>a.ID==GroupID); + public async Task CHeckGroupMemberCompany(int GroupID, int CompanyID)=> + await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID); + } } diff --git a/Hushian.Application/Services/UserService.cs b/Hushian.Application/Services/UserService.cs new file mode 100644 index 0000000..c111666 --- /dev/null +++ b/Hushian.Application/Services/UserService.cs @@ -0,0 +1,18 @@ +using Hushian.Application.Contracts.Persistence; +using Hushian.Domain.Entites; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Application.Services +{ + public class UserService + { + private readonly IGenericRepository _UserRepository; + public async Task AnyUser(int UserID) =>await _UserRepository.Get().AnyAsync(a=>a.ID==UserID); + + } +} diff --git a/Hushian.Domain/Entites/Conversation.cs b/Hushian.Domain/Entites/Conversation.cs index a3de414..91213b5 100644 --- a/Hushian.Domain/Entites/Conversation.cs +++ b/Hushian.Domain/Entites/Conversation.cs @@ -19,8 +19,8 @@ namespace Hushian.Domain.Entites #endregion #region Fild - public string Title { get; set; } - public ConversationStatus Status { get; set; } + public ConversationStatus Status { get; set; } + = ConversationStatus.InProgress; public DateTime? FinishedDateTime { get; set; } public DateTime Cdatetime { get; set; } = DateTime.Now; @@ -33,8 +33,8 @@ namespace Hushian.Domain.Entites public User User { get; set; } [ForeignKey("GroupID")] public Group? Group { get; set; } - public ICollection conversationItems { get; set; } - = new List(); + public ICollection ConversationResponses { get; set; } + = new List(); #endregion } } diff --git a/Hushian.Domain/Entites/ConversationItem.cs b/Hushian.Domain/Entites/ConversationResponse.cs similarity index 91% rename from Hushian.Domain/Entites/ConversationItem.cs rename to Hushian.Domain/Entites/ConversationResponse.cs index b37286b..ccbedfd 100644 --- a/Hushian.Domain/Entites/ConversationItem.cs +++ b/Hushian.Domain/Entites/ConversationResponse.cs @@ -9,12 +9,12 @@ using System.Threading.Tasks; namespace Hushian.Domain.Entites { - public class ConversationItem : BaseEntity + public class ConversationResponse : BaseEntity { #region Key public int ID { get; set; } public int ConversationID { get; set; } - public string? ExperID { get; set; } + public int? ExperID { get; set; } #endregion #region Fild diff --git a/Infrastructure/Persistence/HushianDbContext.cs b/Infrastructure/Persistence/HushianDbContext.cs index 59c51d9..a9604ee 100644 --- a/Infrastructure/Persistence/HushianDbContext.cs +++ b/Infrastructure/Persistence/HushianDbContext.cs @@ -15,7 +15,7 @@ namespace Hushian.Persistence #region Table public DbSet Companies { get; set; } public DbSet Conversations { get; set; } - public DbSet ConversationItems { get; set; } + public DbSet ConversationItems { get; set; } public DbSet Groups { get; set; } public DbSet Expers { get; set; } public DbSet EG { get; set; }