Exemplo n.º 1
0
        public async Task <ChatDto> Handle(CreateChatCommand request, CancellationToken cancellationToken)
        {
            var chatExists = _context.Chats
                             .AsQueryable()
                             .Any(chat => chat.Name == request.Name && chat.OwnerId == request.OwnerId);

            if (chatExists)
            {
                throw new ChatApiException("Could not create chat",
                                           new[] { $"Chat with name {request.Name} already exists for user {request.OwnerId}" });
            }

            var owner = await _usersApiClient.GetUserById(request.OwnerId);

            var chatEntity = new Chat(request.Name, new User(owner.Id, owner.UserName), request.Capacity);

            _chatRepository.Create(chatEntity);
            await _chatRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ChatDto>(chatEntity));
        }
Exemplo n.º 2
0
 public async Task <User> GetUserByIdAsync(int id)
 {
     return(await apiClient.GetUserById(id));
 }