public async Task <IActionResult> ConsultantChatsPagingList([FromBody] ConsultantChatsFilterModel filterModel, int pageIndex, int limit) { var result = await _consultancyService.GetConsultantChatsPagingListAsync(CurrentUserName, filterModel, RequestLang, pageIndex); return(Ok(result)); }
// Get chats for consultant public async Task <ConsultantChatsResultDTO> GetConsultantChatsPagingListAsync(string doctorUserMobile, ConsultantChatsFilterModel filterModel, Lang lang, int page = 0, int pageSize = 12) { var doctorPerson = await _dbContext.Persons.FirstOrDefaultAsync(x => x.Mobile == doctorUserMobile); if (doctorPerson == null) { throw new AwroNoreException("Doctor person not found"); } var serviceSupplieIds = await _dbContext.ServiceSupplies.Where(x => x.PersonId == doctorPerson.Id && x.ConsultancyEnabled).Select(x => x.Id).ToListAsync(); var query = _dbContext.Consultancies.Where(x => x.Status != ConsultancyStatus.REMOVED_BY_DOCTOR); query = query.Where(x => x.Status == filterModel.Status && serviceSupplieIds.Contains(x.ServiceSupplyId)); query = query.Where(x => x.ConsultancyMessages.Any()); var totalCount = await query.CountAsync(); query = query.OrderByDescending(x => x.CreatedAt).Skip(pageSize * page).Take(pageSize); var chats = await query.Select(x => new ConsultantChatsDTO { Id = x.Id, PersonId = x.PersonId, ServiceSupplyId = x.ServiceSupplyId, FinishedAt = x.FinishedAt != null ? x.FinishedAt.ToString() : "", StartedAt = x.StartedAt != null ? x.StartedAt.ToString() : "", Status = x.Status, PersonName = lang == Lang.KU ? x.Person.FullName_Ku : lang == Lang.AR ? x.Person.FullName_Ar : x.Person.FullName, PersonAvatar = x.Person.RealAvatar, LastMessage = x.ConsultancyMessages.Any() ? x.ConsultancyMessages.OrderByDescending(m => m.CreatedAt).FirstOrDefault().Type == ConsultancyMessageType.PHOTO ? Global.Photo : x.ConsultancyMessages.OrderByDescending(m => m.CreatedAt).FirstOrDefault().Type == ConsultancyMessageType.VOICE ? Global.Voice : x.ConsultancyMessages.OrderByDescending(m => m.CreatedAt).FirstOrDefault().Content : "", }).ToListAsync(); var result = new ConsultantChatsResultDTO { TotalCount = totalCount, Chats = chats }; return(result); }