示例#1
0
        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);
        }
示例#2
0
        /// <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);
        }
示例#3
0
 public ChatListingViewModel(ChatListing model)
 {
     Messages = model.Messages.Select(x => new ChatMessageViewModel(x)).ToList();
 }
示例#4
0
 public ChatListingViewModel(ChatListing model, string currentUserId = "")
 {
     Messages   = model.Messages.Select(x => new ChatMessageViewModel(x, currentUserId)).ToList();
     TotalCount = model.TotalCount;
 }