Пример #1
0
        public async Task <List <GetChatDto> > GetChatsAsync(GetChatsRequestDto request)
        {
            var user = await this._unit.UserRepository.GetUserWithBlackList(request.UserName);

            if (user == null)
            {
                throw new UserNotExistException("Given user not exist!", 400);
            }

            var chatres = await _unit.ChatRepository.GetUserChatsAsync(user.Id);

            var res = new List <GetChatDto>();

            foreach (var chat in chatres)
            {
                res.Add(new GetChatDto()
                {
                    Id           = chat.Id,
                    Photo        = chat.FirstUserId == user.Id ? chat.SecondUser.Photo.Name : chat.FirstUser.Photo.Name,
                    Content      = chat.LastMessage == null ? null : chat.LastMessage.Content,
                    SecondUserId = chat.FirstUserId == user.Id ? chat.SecondUserId : chat.FirstUserId,
                    IsBlocked    = user.BlockedUsers.Any(bl => bl.UserToBlockId == chat.SecondUserId || bl.UserToBlockId == chat.FirstUserId) ? true : false
                });
            }

            return(res);
        }
Пример #2
0
        public async Task <List <GetChatDto> > GetChats([FromQuery] GetChatsRequestDto request)
        {
            request.UserName = User.Identity.Name;

            return(await _chatService.GetChatsAsync(request));
        }