public async Task <MessageCommentResponse> SendComment(AddMessageCommentRequest request) { User user = await _userManager.FindByEmailAsync(_contextAccessor.HttpContext.User.Identity.Name); MessageComment comment = _dbContext.MessageComments.FirstOrDefault(x => x.MessageId == request.MessageId); if (comment != null) { request.MessageId = comment.MessageId; } else { if (_dbContext.Messages.All(x => x.Id != request.MessageId)) { throw new BadRequestException($"MessageId = {request.MessageId} does not exists"); } } var newComment = _mapper.Map <MessageComment>(request); newComment.UserId = user.Id; newComment.CreatedAt = DateTime.UtcNow; _dbContext.Add(newComment); Message message = _dbContext.Messages.FirstOrDefault(x => x.Id == newComment.MessageId); if (message != null) { message.DeleteAt = message.DeleteAt?.Add(_messageExtraLifeTime); _dbContext.Entry(message).State = EntityState.Modified; } await _dbContext.SaveChangesAsync(); return(_mapper.Map <MessageCommentResponse>(newComment)); }
public async Task <MessageCommentResponse> SendComment(AddMessageCommentRequest request) { return(await _messageCommentService.SendComment(request)); }