diff --git a/Common/Dtos/Conversation/Read_ConversationDto.cs b/Common/Dtos/Conversation/Read_ConversationDto.cs index f3e7aa0..77e222a 100644 --- a/Common/Dtos/Conversation/Read_ConversationDto.cs +++ b/Common/Dtos/Conversation/Read_ConversationDto.cs @@ -5,7 +5,8 @@ namespace Common.Dtos.Conversation public class Read_ConversationDto { public int ID { get; set; } - public string Title { get; set; } + public string LastText { get; set; } + public ConversationType LastMsgType { get; set; } public ConversationStatus status { get; set; } public int? GroupID { get; set; } @@ -17,8 +18,8 @@ namespace Common.Dtos.Conversation public int? ExperID { get; set; } public string? ExperFullName { get; set; } - public string Cdate { get; set; } - public string Ctime { get; set; } + public string LastMsgdate { get; set; } + public string LastMsgtime { get; set; } public int NoReadCount { get; set; } = 0; } } diff --git a/Hushian.Application/Services/ConversationService.cs b/Hushian.Application/Services/ConversationService.cs index fa9161a..9e83333 100644 --- a/Hushian.Application/Services/ConversationService.cs +++ b/Hushian.Application/Services/ConversationService.cs @@ -93,13 +93,89 @@ namespace Hushian.Application.Services 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(); } + public async Task> MyConversation(int UserID) + => await _ConversationRepository.Get() + .Include(inc => inc.Group) + .Include(inc => inc.ConversationResponses).ThenInclude(tinc => tinc.Exper) + .Where(w => w.UserID == UserID) + .Select(s => new Read_ConversationDto() + { + ExperID = s.ConversationResponses.Last().ExperID, + ExperFullName = s.ConversationResponses.Last().Exper.FullName, + GroupID = s.GroupID, + GroupName = s.Group.Name, + LastText = s.ConversationResponses.Last().Text, + LastMsgdate = s.Cdatetime.GetDatePersian(), + LastMsgtime = s.Cdatetime.GetTime(), + LastMsgType = s.ConversationResponses.Last().Type, + NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), + status = s.Status, + UserID = s.UserID, + UserFullName = s.User.FullName + + }).ToListAsync(); + public async Task> MyConversationIsFinished(int ExperID) + => 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) + .Select(s => new Read_ConversationDto() + { + ExperID = s.ConversationResponses.Last().ExperID, + ExperFullName = s.ConversationResponses.Last().Exper.FullName, + GroupID = s.GroupID, + GroupName = s.Group.Name, + LastText = s.ConversationResponses.Last().Text, + LastMsgdate = s.Cdatetime.GetDatePersian(), + LastMsgtime = s.Cdatetime.GetTime(), + LastMsgType = s.ConversationResponses.Last().Type, + NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), + status = s.Status, + UserID = s.UserID, + UserFullName = s.User.FullName + + }).ToListAsync(); + public async Task> MyConversationIsInProgress(int ExperID) + => 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) + .Select(s => new Read_ConversationDto() + { + ExperID = s.ConversationResponses.Last().ExperID, + ExperFullName = s.ConversationResponses.Last().Exper.FullName, + GroupID = s.GroupID, + GroupName = s.Group.Name, + LastText = s.ConversationResponses.Last().Text, + LastMsgdate = s.Cdatetime.GetDatePersian(), + LastMsgtime = s.Cdatetime.GetTime(), + LastMsgType = s.ConversationResponses.Last().Type, + NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), + status = s.Status, + UserID = s.UserID, + UserFullName = s.User.FullName + + }).ToListAsync(); + public async Task> ConversationAwaitingOurResponse(int CompanyID) + => 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) + .Select(s => new Read_ConversationDto() + { + ExperID = s.ConversationResponses.Last().ExperID, + ExperFullName = s.ConversationResponses.Last().Exper.FullName, + GroupID = s.GroupID, + GroupName = s.Group.Name, + LastText = s.ConversationResponses.Last().Text, + LastMsgdate = s.Cdatetime.GetDatePersian(), + LastMsgtime = s.Cdatetime.GetTime(), + LastMsgType = s.ConversationResponses.Last().Type, + NoReadCount = s.ConversationResponses.Count(c => !c.IsRead), + status = s.Status, + UserID = s.UserID, + UserFullName = s.User.FullName + + }).ToListAsync(); } } diff --git a/Hushian.Application/Services/ExMethod.cs b/Hushian.Application/Services/ExMethod.cs new file mode 100644 index 0000000..fa55bf5 --- /dev/null +++ b/Hushian.Application/Services/ExMethod.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Application.Services +{ + public static class ExMethod + { + public static string GetDatePersian(this DateTime d) + { + PersianCalendar pc = new PersianCalendar(); + return string.Format("{0}/{1}/{2}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d)); + } + public static string GetTime(this DateTime d) + { + return d.Hour.ToString() + ":" + d.Minute.ToString(); + } + } +}