Ejemplo n.º 1
0
        public List <MessageViewModel> Get(string type, string applicationUserIdCurrent, int?skip, int?take, int chatId)
        {
            IEnumerable <MessageEntity> messages = repositoryOfMessage.ReadMany(
                new Expression <Func <MessageEntity, bool> >[] { a => a.ChatRoomId == chatId },
                "Created",
                new Expression <Func <MessageEntity, object> >[] { a => a.UserProfile })
                                                   .Reverse();

            messages = (skip != null) ? messages.Skip(skip.Value) : messages;
            messages = (take != null) ? messages.Take(take.Value) : messages;
            var messagesViewModel = messages
                                    .Select(messageEntity =>
            {
                var message    = mapper.Map <MessageEntity, MessageViewModel>(messageEntity);
                message.Author = serviceOfUser.GetUsers(a => a.UserProfileId == messageEntity.UserProfileId).First();
                return(message);
            })
                                    .AsParallel()
                                    .ToList();

            return(messagesViewModel);
        }
        public List <ChatRoomViewModel> Get(string type, string applicationUserIdCurrent, int?skip, int?take)
        {
            IEnumerable <UserChatEntity> userChatEntities = repositoryOfUserChat.ReadMany(
                new Expression <Func <UserChatEntity, bool> >[] { a => a.UserProfile.ApplicationUserId == applicationUserIdCurrent },
                null,
                a => a.ChatRoom,
                a => a.UserProfile);

            userChatEntities = (skip != null) ? userChatEntities.Skip(skip.Value) : userChatEntities;
            userChatEntities = (take != null) ? userChatEntities.Take(take.Value) : userChatEntities;
            var chatRoomViewModel = userChatEntities
                                    .Select(a =>
            {
                var chat = mapper.Map <UserChatEntity, ChatRoomViewModel>(a);
                // chat.Messages = serviceOfMessage.Get(null, applicationUserIdCurrent, null, 10, chat.Id);
                chat.Users = serviceOfUser.GetUsers(new Expression <Func <ApplicationUserEntity, bool> >[] { b => a.ChatRoom.UserChats.Select(user => user.UserId).Any(id => id == b.UserProfileId) });
                return(chat);
            })
                                    .AsParallel()
                                    .ToList();

            return(chatRoomViewModel);
        }