public async Task <ChatListing> GetMessagesAsync(ElanUser user1, ElanUser user2, int skip = 0, int take = 10) { var messagesQuery = _dataService .GetSet <ChatMessage>() .Where(m => (m.UserFromId == user1.Id && m.UserToId == user2.Id) || (m.UserFromId == user2.Id && m.UserToId == user1.Id)); var totalCount = messagesQuery.Count(); var messages = await messagesQuery .OrderByDescending(m => m.SentOn) .Skip(skip * take) .Take(take) .OrderBy(m => m.SentOn) .ToListAsync(); var model = new ChatListing { TotalCount = totalCount, Messages = messages }; return(model); }
/// <summary>Gets the messages asynchronous.</summary> /// <param name="skip">The skip.</param> /// <param name="take">The take.</param> /// <returns></returns> public async Task <ChatListing> GetMessagesAsync(int skip = 0, int take = 10) { var query = _dataService.GetSet <ChatMessage>(); var messages = await query .OrderByDescending(m => m.SendTime) .Skip(skip * take) .Take(take) .OrderBy(m => m.SendTime) .ToListAsync(); var model = new ChatListing { Messages = messages }; return(model); }
public ChatListingViewModel(ChatListing model) { Messages = model.Messages.Select(x => new ChatMessageViewModel(x)).ToList(); }
public ChatListingViewModel(ChatListing model, string currentUserId = "") { Messages = model.Messages.Select(x => new ChatMessageViewModel(x, currentUserId)).ToList(); TotalCount = model.TotalCount; }