...
This commit is contained in:
@@ -3,6 +3,7 @@ namespace Common.Dtos.Conversation
|
|||||||
{
|
{
|
||||||
public class ADD_ConversationDto
|
public class ADD_ConversationDto
|
||||||
{
|
{
|
||||||
|
public int UserID { get; set; }
|
||||||
public string Question { get; set; }
|
public string Question { get; set; }
|
||||||
public int? GroupID { get; set; }
|
public int? GroupID { get; set; }
|
||||||
public int CompanyID { get; set; }
|
public int CompanyID { get; set; }
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
|
|
||||||
|
using Common.Enums;
|
||||||
|
|
||||||
namespace Common.Dtos.Conversation
|
namespace Common.Dtos.Conversation
|
||||||
{
|
{
|
||||||
public class ADD_ConversationItemDto
|
public class ADD_ConversationResponseDto
|
||||||
{
|
{
|
||||||
public int ConversationID { get; set; }
|
public int ConversationID { get; set; }
|
||||||
|
public ConversationType Type { get; set; }
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
public string? FileName { get; set; }
|
public string? FileName { get; set; }
|
||||||
public string? FileType { get; set; }
|
public string? FileType { get; set; }
|
@@ -8,6 +8,6 @@ namespace Common.Enums
|
|||||||
{
|
{
|
||||||
public enum ConversationType
|
public enum ConversationType
|
||||||
{
|
{
|
||||||
EU = 1, UE = 2
|
EU = 1, UE = 2,Bot=3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -195,6 +195,8 @@ namespace Hushian.Application.Services
|
|||||||
|
|
||||||
return Response;
|
return Response;
|
||||||
}
|
}
|
||||||
|
public async Task<bool> AnyCompany(int CompanyID)
|
||||||
|
=>await _CompanyRepository.Get().AnyAsync(a=>a.ID==CompanyID);
|
||||||
private async Task<int> Verifi(string Mobile) => await _VerificationService.GenerateCodeByPhoneNumberConfirmed(Mobile);
|
private async Task<int> Verifi(string Mobile) => await _VerificationService.GenerateCodeByPhoneNumberConfirmed(Mobile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
105
Hushian.Application/Services/ConversationService.cs
Normal file
105
Hushian.Application/Services/ConversationService.cs
Normal file
@@ -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<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 async Task<ResponseBase<int>> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
|
||||||
|
{
|
||||||
|
var Response = new ResponseBase<int>();
|
||||||
|
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<ConversationResponse>() { 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<ResponseBase<int>> NewConversationResponse(ADD_ConversationResponseDto dto, int? ExperID)
|
||||||
|
{
|
||||||
|
var Response = new ResponseBase<int>();
|
||||||
|
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<List<Read_ConversationDto>> MyConversation(int CompanyID, string UserID)
|
||||||
|
{ return new(); }
|
||||||
|
public async Task<List<Read_ConversationDto>> MyConversationIsFinished(int CompanyID, string? ExperID = null)
|
||||||
|
{ return new(); }
|
||||||
|
public async Task<List<Read_ConversationDto>> MyConversationIsInProgress(int CompanyID, string ExperID)
|
||||||
|
{ return new(); }
|
||||||
|
public async Task<List<Read_ConversationDto>> ConversationAwaitingOurResponse(int CompanyID, string? ExperID = null)
|
||||||
|
{ return new(); }
|
||||||
|
}
|
||||||
|
}
|
@@ -110,11 +110,11 @@ namespace Hushian.Application.Services
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
public async Task<bool> AnyGroup(int GroupID) =>
|
||||||
public async Task<bool> CHeckGroupMemberCompany(int GroupID, int CompanyID)
|
await _GroupRepository.Get().AnyAsync(a=>a.ID==GroupID);
|
||||||
{
|
public async Task<bool> CHeckGroupMemberCompany(int GroupID, int CompanyID)=>
|
||||||
return await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID);
|
await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
Hushian.Application/Services/UserService.cs
Normal file
18
Hushian.Application/Services/UserService.cs
Normal file
@@ -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<User> _UserRepository;
|
||||||
|
public async Task<bool> AnyUser(int UserID) =>await _UserRepository.Get().AnyAsync(a=>a.ID==UserID);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -19,8 +19,8 @@ namespace Hushian.Domain.Entites
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Fild
|
#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? FinishedDateTime { get; set; }
|
||||||
public DateTime Cdatetime
|
public DateTime Cdatetime
|
||||||
{ get; set; } = DateTime.Now;
|
{ get; set; } = DateTime.Now;
|
||||||
@@ -33,8 +33,8 @@ namespace Hushian.Domain.Entites
|
|||||||
public User User { get; set; }
|
public User User { get; set; }
|
||||||
[ForeignKey("GroupID")]
|
[ForeignKey("GroupID")]
|
||||||
public Group? Group { get; set; }
|
public Group? Group { get; set; }
|
||||||
public ICollection<ConversationItem> conversationItems { get; set; }
|
public ICollection<ConversationResponse> ConversationResponses { get; set; }
|
||||||
= new List<ConversationItem>();
|
= new List<ConversationResponse>();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,12 +9,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Hushian.Domain.Entites
|
namespace Hushian.Domain.Entites
|
||||||
{
|
{
|
||||||
public class ConversationItem : BaseEntity
|
public class ConversationResponse : BaseEntity
|
||||||
{
|
{
|
||||||
#region Key
|
#region Key
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
public int ConversationID { get; set; }
|
public int ConversationID { get; set; }
|
||||||
public string? ExperID { get; set; }
|
public int? ExperID { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Fild
|
#region Fild
|
@@ -15,7 +15,7 @@ namespace Hushian.Persistence
|
|||||||
#region Table
|
#region Table
|
||||||
public DbSet<Company> Companies { get; set; }
|
public DbSet<Company> Companies { get; set; }
|
||||||
public DbSet<Conversation> Conversations { get; set; }
|
public DbSet<Conversation> Conversations { get; set; }
|
||||||
public DbSet<ConversationItem> ConversationItems { get; set; }
|
public DbSet<ConversationResponse> ConversationItems { get; set; }
|
||||||
public DbSet<Group> Groups { get; set; }
|
public DbSet<Group> Groups { get; set; }
|
||||||
public DbSet<Exper> Expers { get; set; }
|
public DbSet<Exper> Expers { get; set; }
|
||||||
public DbSet<ExperGroup> EG { get; set; }
|
public DbSet<ExperGroup> EG { get; set; }
|
||||||
|
Reference in New Issue
Block a user