public async Task <IActionResult> UpdateFile(string folderId, string fileId, FileForUpdateDto fileForUpdateDto) { try { Guid.TryParse(User.FindFirst(ClaimTypes.NameIdentifier).Value, out Guid userId); Guid fileForRepoId = new Guid(fileId); Guid folderForRepoId = new Guid(folderId); Folder folder = await _repo.GetFolder(folderForRepoId); Models.File file = await _repo.GetFile(fileForRepoId); if (userId != folder.UserId && folder.Id != file.FolderId) { return(Unauthorized()); } file.FileName = fileForUpdateDto.Name; if (await _repo.SaveAll()) { return(NoContent()); } return(BadRequest("There was a problem updating file information")); } catch (Exception ex) { return(StatusCode(400, ex.Message)); } }
public async Task <IActionResult> UpdateFile(int id, FileForUpdateDto fileForUpdateDto) { var fileFromRepo = await _repo.GetFile(id); if (fileFromRepo == null) { return(NotFound()); } _mapper.Map(fileForUpdateDto, fileFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating File {id} failed on save"); }