public IDataResult <ChatComment> CreateChatComment(AddChatCommentDto addChatDto) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), CheckReceiverIsExist(addChatDto.ReceiverId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <ChatComment>(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; var chat = GetChatById(user.Id, addChatDto.ReceiverId).Data; if (chat == null) { var result = CreateChatwithComment(user, addChatDto); return(new SuccessDataResult <ChatComment>(GetChatCommentById(result.Data).Data, Message.ChatCommentCreated)); } var chatComment = new ChatComment() { UserId = user.Id, ChatId = chat.Id, Comment = addChatDto.Content }; _uow.ChatComments.Add(chatComment); _uow.Commit(); return(new SuccessDataResult <ChatComment>(GetChatCommentById(chatComment.Id).Data, Message.ChatCommentCreated)); }
private IDataResult <long> CreateChatwithComment(User user, AddChatCommentDto addChatDto) { var chat = new Chat() { FirstUserId = user.Id, SecondUserId = addChatDto.ReceiverId }; var chatComment = new ChatComment() { UserId = user.Id, Comment = addChatDto.Content }; chat.ChatComments.Add(chatComment); _uow.Chats.Add(chat); _uow.Commit(); return(new SuccessDataResult <long>(chatComment.Id)); }
public IActionResult CreateChatComment(AddChatCommentDto addChatCommentDto) { var result = _chatService.CreateChatComment(addChatCommentDto); if (result.ResultType == ResultType.UnAuthorized) { return(Unauthorized()); } if (result.ResultType == ResultType.Success) { return(Ok(result)); } return(BadRequest(result.Message)); }