public async Task <DirectMessageResult> SendDirectMessageAsync(SendDirectMessageDto sendDirectMessageDto) { var toUser = await _accountService.GetAccountByIdAsync(sendDirectMessageDto.ToId); if (toUser == null) { return(DirectMessageResult.Fail(new ErrorList().AddError("ToId", "User not found"))); } var directMessage = new DirectMessage(sendDirectMessageDto.MessageText, sendDirectMessageDto.From, toUser); await _directMessageRepository.InsertAsync(directMessage); await _directMessageRepository.CommitAsync(); return(DirectMessageResult.Ok(directMessage)); }
public async Task <DirectMessageResult> MarkAsRead(ApplicationUser loggedUser, Guid directMessageId) { var directMessage = await _directMessageRepository.GetFirstAsync(new DirectMessageIdEqualSpecification(directMessageId)); if (directMessage == null) { return(DirectMessageResult.Fail(new ErrorList().AddError("DirectMessageId", "Direct message not found."))); } if (directMessage.From.Id != loggedUser.Id) { return(DirectMessageResult.Fail(new ErrorList().AddError("DirectMessageId", "Direct message was not sent to you."))); } directMessage.MarkRead(); await _directMessageRepository.UpdateAsync(directMessage); await _directMessageRepository.CommitAsync(); return(DirectMessageResult.Ok(directMessage)); }