public void Execute(ChangeCommentDto request) { Comment item = context.Comments.Find(request.Id); if (request.Text != null) { item.Text = request.Text; } if (request.ApplicationUserId != null) { item.ApplicationUserId = (int)request.ApplicationUserId; } if (request.TicketId != null) { item.TicketId = (int)request.TicketId; } item.UpdatedAt = DateTime.Now; context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Detached; var tp = context.Comments.Attach(item); tp.State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); }
public IActionResult Put(int id, [FromBody] ChangeCommentDto dto , [FromServices] IChangeCommentCommand command , [FromServices] ChangeCommentValidator validator) { var result = validator.Validate(dto); if (result.IsValid) { dto.Id = id; _useCaseExecutor.ExecuteCommand(command, dto); return(Ok("Comment updated successfully")); } return(UnprocessableEntity(UnprocessableEntityResponse.Message(result.Errors))); }