/// <summary> /// Reading page of messages of chat by Id /// </summary> /// <param name="chatModel"></param> /// <returns></returns> public List <MessageResponseModel> ReadPage(ChatPaginationReceiveModel chatModel) { using (DatabaseContext context = new DatabaseContext()) { var messages = context.Messages.Where(m => m.ChatId == chatModel.ChatId); messages.Reverse(); return(messages .Skip(chatModel.Page * 30) .Take(30) .Select(m => new MessageResponseModel() { Id = m.Id, UserMassage = m.UserMessage, ChatId = m.ChatId, UserId = m.FromUserId, IsReaded = m.IsReaded, Date = m.Date, File = string.IsNullOrEmpty(m.FileName) ? null : new FileModel() { FileName = m.FileName, Extension = m.FileExtension, BinaryForm = m.File } }) .ToList()); } }
public OperationResultInfo GetChatMessages(ChatPaginationReceiveModel model) { try { var messagesPage = _messageLogic.ReadPage(model); return(new OperationResultInfo() { ErrorInfo = string.Empty, OperationResult = OperationsResults.Successfully, ToListener = ListenerType.ChatsMessagesListener, JsonData = messagesPage }); } catch (Exception ex) { return(new OperationResultInfo() { ErrorInfo = ex.Message, OperationResult = OperationsResults.Unsuccessfully, ToListener = ListenerType.ChatsMessagesListener }); } }