...
This commit is contained in:
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Hushian.Application.Services
|
||||
{
|
||||
public class ChatService
|
||||
public class ChatService
|
||||
{
|
||||
private readonly IGenericRepository<Conversation> _ConversationRepository;
|
||||
private readonly IGenericRepository<ConversationResponse> _ConversationResponseRepository;
|
||||
@@ -55,7 +55,7 @@ namespace Hushian.Application.Services
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss=>new ChatItemResponseDto()
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
@@ -104,40 +104,50 @@ namespace Hushian.Application.Services
|
||||
}).ToList()
|
||||
|
||||
}).ToListAsync();
|
||||
public async Task<List<ChatItemDto>> ChatsAwaitingOurResponse(int CompanyID)
|
||||
=> await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.Status == ConversationStatus.Recorded && w.CompanyID == CompanyID)
|
||||
.Select(s => new ChatItemDto()
|
||||
public async Task<List<ChatItemDto>> ChatsAwaitingOurResponse(int CompanyID, int? ExperID)
|
||||
{
|
||||
ID = s.ID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
|
||||
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
|
||||
GroupID = s.GroupID,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
int[]? groupallow = null;
|
||||
if (ExperID.HasValue)
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
}).ToList()
|
||||
var groups = await _groupService.GetGroupsExper(ExperID.Value);
|
||||
if (groups.Count > 0) groupallow = groups.Select(s => s.ID).ToArray();
|
||||
}
|
||||
|
||||
}).ToListAsync();
|
||||
var request = _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.Status == ConversationStatus.Recorded && w.CompanyID == CompanyID);
|
||||
if (groupallow != null) request = request.Where(w=>!w.GroupID.HasValue || groupallow.Contains(w.GroupID.Value));
|
||||
return await request.Select(s => new ChatItemDto()
|
||||
{
|
||||
ID = s.ID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
|
||||
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
|
||||
GroupID = s.GroupID,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
}).ToList()
|
||||
|
||||
}).ToListAsync();
|
||||
}
|
||||
//------------------------
|
||||
public async Task<ResponseBase<ChatItemDto>> NewChat(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
|
||||
{
|
||||
@@ -167,39 +177,39 @@ namespace Hushian.Application.Services
|
||||
ConversationResponses = new List<ConversationResponse>() { new() { Text = dto.Question, Type = type } }
|
||||
};
|
||||
var mi = await _ConversationRepository.ADD(conversation);
|
||||
if(mi.ID > 0)
|
||||
Response.Value = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group).Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.ID==mi.ID)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
ID = s.ID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
|
||||
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
|
||||
GroupID = s.GroupID,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
}).ToList()
|
||||
if (mi.ID > 0)
|
||||
Response.Value = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group).Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.ID == mi.ID)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
ID = s.ID,
|
||||
ExperID = s.ConversationResponses.OrderBy(o => o.ID).Last().ExperID,
|
||||
ExperFullName = s.ConversationResponses.OrderBy(o => o.ID).Last().Exper.FullName,
|
||||
GroupID = s.GroupID,
|
||||
GroupName = s.Group.Name,
|
||||
LastText = s.ConversationResponses.OrderBy(o => o.ID).Last().Text,
|
||||
LastMsgdate = s.Cdatetime.GetDatePersian(),
|
||||
LastMsgtime = s.Cdatetime.GetTime(),
|
||||
LastMsgType = s.ConversationResponses.OrderBy(o => o.ID).Last().Type,
|
||||
status = s.Status,
|
||||
UserID = s.UserID,
|
||||
UserFullName = string.IsNullOrEmpty(s.User.FullName) ? s.User.Mobile : s.User.FullName,
|
||||
Responses = s.ConversationResponses.Select(ss => new ChatItemResponseDto()
|
||||
{
|
||||
ChatItemID = ss.ConversationID,
|
||||
ExperID = ss.ExperID,
|
||||
ExperName = ss.Exper.FullName,
|
||||
FileContent = ss.FileContent,
|
||||
FileName = ss.FileName,
|
||||
FileType = ss.FileType,
|
||||
ID = ss.ID,
|
||||
IsRead = ss.IsRead,
|
||||
text = ss.Text,
|
||||
Type = ss.Type
|
||||
}).ToList()
|
||||
|
||||
}).FirstOrDefaultAsync();
|
||||
}).FirstOrDefaultAsync();
|
||||
Response.Success = mi.ID > 0;
|
||||
}
|
||||
else Response.Errors.Add("شناسه گروه صحیح نمی باشد");
|
||||
@@ -272,11 +282,11 @@ namespace Hushian.Application.Services
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<bool> FinishChat(int ChatID, int CompanyID,int? ExperID)
|
||||
public async Task<bool> FinishChat(int ChatID, int CompanyID, int? ExperID)
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
.FirstOrDefaultAsync(w => w.ID == ChatID && w.CompanyID==CompanyID);
|
||||
.FirstOrDefaultAsync(w => w.ID == ChatID && w.CompanyID == CompanyID);
|
||||
if (ExperID.HasValue && !convModel.ConversationResponses.Any(a => a.ExperID == ExperID.Value)) return false;
|
||||
|
||||
if (convModel != null && convModel.Status != ConversationStatus.Finished)
|
||||
@@ -288,7 +298,7 @@ namespace Hushian.Application.Services
|
||||
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> OpenChat(int ChatID, int CompanyID,int? ExperID)
|
||||
public async Task<bool> OpenChat(int ChatID, int CompanyID, int? ExperID)
|
||||
{
|
||||
var convModel = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.ConversationResponses)
|
||||
@@ -322,7 +332,11 @@ namespace Hushian.Application.Services
|
||||
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> Attachedto(int ChatID, int? FromExperID, int toExperID, int CompanyID)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
public async Task<bool> MarkAsReadChatItem(int ID, ConversationType Type, int? ExperID)
|
||||
{
|
||||
var item = await _ConversationResponseRepository.Get()
|
||||
@@ -352,14 +366,14 @@ namespace Hushian.Application.Services
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public async Task<ResponseBase<ChatItemDto>> GetLastOpenChatInCompany(int CompanyID,int UserID)
|
||||
public async Task<ResponseBase<ChatItemDto>> GetLastOpenChatInCompany(int CompanyID, int UserID)
|
||||
{
|
||||
ResponseBase<ChatItemDto> Response = new();
|
||||
Response.Value= await _ConversationRepository.Get()
|
||||
Response.Value = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.UserID== UserID &&w.CompanyID==CompanyID && w.Status != ConversationStatus.Finished)
|
||||
.OrderByDescending(o=>o.ID)
|
||||
.Where(w => w.UserID == UserID && w.CompanyID == CompanyID && w.Status != ConversationStatus.Finished)
|
||||
.OrderByDescending(o => o.ID)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
ID = s.ID,
|
||||
@@ -399,7 +413,7 @@ namespace Hushian.Application.Services
|
||||
Response.Value = await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.UserID == UserID && w.ID == ChatID )
|
||||
.Where(w => w.UserID == UserID && w.ID == ChatID)
|
||||
.OrderByDescending(o => o.ID)
|
||||
.Select(s => new ChatItemDto()
|
||||
{
|
||||
|
Reference in New Issue
Block a user