public async Task <IActionResult> EditDocument([FromBody] DocumentEditDto model) { var currentUser = await _identityService.GetCurrentPersonIdentityAsync(); if (currentUser == null) { return(BadRequest(new MessageDto() { Success = true, Message = "Invalid user" })); } if (ModelState.IsValid) { var document = await _documentService.GetDocumentById(model.Id); if (document == null) { return(BadRequest(new MessageDto() { Success = false, Message = "Bad request!" })); } MessageDto check = await _documentService.CheckIfClientCanEdit(currentUser.Id, document.Id); if (!check.Success) { return(BadRequest(new MessageDto() { Success = false, Message = "You can't edit this document." })); } document.Subject = model.Subject; document.Title = model.Title; var result = await _documentService.EditDocument(document); if (result.Success) { return(new OkObjectResult(result)); } return(BadRequest(result)); } return(BadRequest(new MessageDto() { Success = false, Message = "Bad request!" })); }