...
This commit is contained in:
@@ -4,6 +4,8 @@ using Common.Enums;
|
||||
using Hushian.Application.Contracts.Persistence;
|
||||
using Hushian.Application.Models;
|
||||
using Hushian.Domain.Entites;
|
||||
using Hushian.WebApi;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.VisualBasic;
|
||||
using System;
|
||||
@@ -22,12 +24,13 @@ namespace Hushian.Application.Services
|
||||
private readonly UserService _userService;
|
||||
private readonly GroupService _groupService;
|
||||
private readonly ExperService _experService;
|
||||
private readonly IHubContext<ChatNotificationHub> _hubContext;
|
||||
|
||||
public ConversationService(
|
||||
IGenericRepository<Conversation> conversationRepository
|
||||
, IGenericRepository<ConversationResponse> conversationResponseRepository
|
||||
, CompanyService companyService, UserService userService, GroupService groupService
|
||||
, ExperService experService)
|
||||
, ExperService experService, IHubContext<ChatNotificationHub> hubContext)
|
||||
{
|
||||
_ConversationRepository = conversationRepository;
|
||||
_ConversationResponseRepository = conversationResponseRepository;
|
||||
@@ -35,6 +38,7 @@ namespace Hushian.Application.Services
|
||||
_userService = userService;
|
||||
_groupService = groupService;
|
||||
_experService = experService;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
public async Task<ResponseBase<int>> NewConversation(ADD_ConversationDto dto, ConversationType type = ConversationType.UE)
|
||||
@@ -112,17 +116,23 @@ namespace Hushian.Application.Services
|
||||
};
|
||||
Response.Value = (await _ConversationResponseRepository.ADD(response)).ID;
|
||||
Response.Success = Response.Value > 0;
|
||||
|
||||
if (convModel.Status == ConversationStatus.Recorded && Response.Success)
|
||||
{
|
||||
convModel.Status = ConversationStatus.InProgress;
|
||||
await _ConversationRepository.UPDATE(convModel);
|
||||
}
|
||||
}
|
||||
else Response.Errors.Add("گفتگویی یافت نشد");
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
public async Task<List<Read_ConversationDto>> MyConversation(int UserID)
|
||||
public async Task<List<Read_ConversationDto>> GEtConversation(int UserID,int CompanyID)
|
||||
=> await _ConversationRepository.Get()
|
||||
.Include(inc => inc.Group)
|
||||
.Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper)
|
||||
.Where(w => w.UserID == UserID)
|
||||
.Where(w => w.UserID == UserID && w.CompanyID==CompanyID)
|
||||
.Select(s => new Read_ConversationDto()
|
||||
{
|
||||
ExperID = s.ConversationResponses.Last().ExperID,
|
||||
@@ -139,11 +149,32 @@ namespace Hushian.Application.Services
|
||||
UserFullName = s.User.FullName
|
||||
|
||||
}).ToListAsync();
|
||||
public async Task<List<Read_ConversationDto>> MyConversationIsFinished(int ExperID)
|
||||
public async Task<List<Read_ConversationResponseDto>> GetConversationItems(int ConversationID, int? ExperID)
|
||||
{
|
||||
return await _ConversationResponseRepository.Get()
|
||||
.Include(inc=>inc.Exper)
|
||||
.Where(w => w.ConversationID == ConversationID)
|
||||
.Select(s => new Read_ConversationResponseDto()
|
||||
{
|
||||
ConversationID=s.ConversationID,
|
||||
ExperID=s.ExperID,
|
||||
ExperName=s.Exper.FullName,
|
||||
FileContent=s.FileContent,
|
||||
FileName=s.FileName,
|
||||
FileType=s.FileType,
|
||||
ID= s.ID,
|
||||
IsRead=s.IsRead,
|
||||
text=s.Text,
|
||||
Type = s.Type
|
||||
}).ToListAsync();
|
||||
|
||||
|
||||
}
|
||||
public async Task<List<Read_ConversationDto>> GetConversationByExperID(int ExperID , ConversationStatus status)
|
||||
=> 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 == status)
|
||||
.Select(s => new Read_ConversationDto()
|
||||
{
|
||||
ExperID = s.ConversationResponses.Last().ExperID,
|
||||
@@ -160,11 +191,11 @@ namespace Hushian.Application.Services
|
||||
UserFullName = s.User.FullName
|
||||
|
||||
}).ToListAsync();
|
||||
public async Task<List<Read_ConversationDto>> MyConversationIsInProgress(int ExperID)
|
||||
public async Task<List<Read_ConversationDto>> GetConversationByCompanyID(int CompanyID, ConversationStatus status)
|
||||
=> 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.InProgress)
|
||||
.Where(w => w.CompanyID==CompanyID && w.Status ==status)
|
||||
.Select(s => new Read_ConversationDto()
|
||||
{
|
||||
ExperID = s.ConversationResponses.Last().ExperID,
|
||||
@@ -185,7 +216,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.HasValue) && w.CompanyID == CompanyID)
|
||||
.Where(w => w.Status== ConversationStatus.Recorded && w.CompanyID == CompanyID)
|
||||
.Select(s => new Read_ConversationDto()
|
||||
{
|
||||
ExperID = s.ConversationResponses.Last().ExperID,
|
||||
@@ -211,10 +242,59 @@ namespace Hushian.Application.Services
|
||||
if (convModel != null && convModel.Status != ConversationStatus.Finished)
|
||||
{
|
||||
convModel.Status = ConversationStatus.Finished;
|
||||
convModel.FinishedDateTime = DateTime.Now;
|
||||
return await _ConversationRepository.UPDATEBool(convModel);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public async Task<bool> MarkAsReadConversationItem(int ID, ConversationType Type , int? ExperID)
|
||||
{
|
||||
var item = await _ConversationResponseRepository.Get()
|
||||
.Include(inc => inc.conversation).FirstOrDefaultAsync(w => w.ID == ID && !w.ExperID.HasValue
|
||||
&& w.conversation.Status != ConversationStatus.Finished);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
if (Type != item.Type)
|
||||
{
|
||||
if (Type != ConversationType.UE && item.conversation.Status == ConversationStatus.Recorded)
|
||||
{
|
||||
item.conversation.Status = ConversationStatus.InProgress;
|
||||
await _ConversationRepository.UPDATE(item.conversation);
|
||||
}
|
||||
|
||||
if (!item.IsRead)
|
||||
{
|
||||
item.IsRead = true;
|
||||
item.ReadDateTime = DateTime.Now;
|
||||
item.ExperID = ExperID;
|
||||
return (await _ConversationResponseRepository.UPDATE(item)) != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public async Task<int> GetCountQueueCompany(int CompanyID, int GroupID = 0)
|
||||
{
|
||||
var request = _ConversationRepository.Get()
|
||||
.Where(w => w.CompanyID == CompanyID && w.Status!=ConversationStatus.Finished);
|
||||
if (GroupID != 0)
|
||||
request = request.Where(w => w.GroupID == GroupID);
|
||||
return await request.CountAsync();
|
||||
}
|
||||
public async Task WriteInHub(ConversationResponse item)
|
||||
{
|
||||
// فرض: لیستی از کاربرانی که به گفتگو دسترسی دارند
|
||||
var usernames = new List<string>();
|
||||
|
||||
foreach (var usn in usernames)
|
||||
{
|
||||
//await _hubContext.Clients.User(usn)
|
||||
// .SendAsync("ReceiveNewConversation", conv.Id, conv.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user