public async Task UpdateFolder(UpdateFolderDto folderDto, int userId, int clientId) { var fileStorageRepository = DataContextManager.CreateRepository <IFileStorageRepository>(); var fileStorage = await fileStorageRepository.GetById(folderDto.Id, userId, clientId); if (fileStorage == null || fileStorage != null && !fileStorage.IsDirectory) { throw new NotFoundException("File storage", folderDto.Id); } var isAvailableToChange = await fileStorageRepository.IsAvailableToChange(fileStorage.Id, userId, clientId); if (!isAvailableToChange) { throw new UnavailableOperationException("update folder", "File storage", fileStorage.Id, userId); } if (fileStorage.ParentFileStorageId.HasValue) { var childFileStorages = await fileStorageRepository.GetByParentId(fileStorage.ParentFileStorageId.Value, userId, clientId); if (childFileStorages.Any(x => x.Name.Equals(folderDto.Name) && x.Id != folderDto.Id)) { throw new FoundSameObjectException("File storage", folderDto.Name); } } fileStorage.Name = folderDto.Name; fileStorage.UpdateById = userId; fileStorage.UpdateDate = DateTime.UtcNow; await fileStorageRepository.Update(fileStorage); }
public async Task <ActionResult> UpdateFolder([FromBody] UpdateFolderDto folderDto) { if (!IsAvailableOperation()) { return(BadRequest()); } await _fileStorageService.UpdateFolder(folderDto, UserId, ClientId); AddLog(Enums.LogType.Create, LogMessage.CreateSuccessByIdMessage(LogMessage.FolderEntityName, folderDto.Id, LogMessage.CreateAction, UserId)); return(Ok()); }
public async void testUpdateFolder() { var client = _factory.CreateClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _projectsEnv._stringDict.GetValueOrDefault("token")); var folder = new UpdateFolderDto { description = "test10", name = "test11", icon = "test13" }; var expectedFolder = new GetFolderDto { description = folder.description, icon = folder.icon, name = folder.name, userId = _projectsEnv._parsedToken.Claims.FirstOrDefault(claim => claim.Type == "nameid").Value }; // Act var actualResponseFolder = await client .testSuccessPutAsync <GetFolderDto, UpdateFolderDto>($"/api/folders/{ _projectsEnv._stringDict.GetValueOrDefault("folderId")}", folder); // Assert expectedFolder.WithDeepEqual(actualResponseFolder.data) .SkipDefault <DateTime>() .IgnoreSourceProperty(x => x.id) .IgnoreDestinationProperty(x => x.dateCreated) .Assert(); // Act var actualResponseFolderGet = await client.testSuccessGetAsync <GetFolderDto>("/api/folders/" + actualResponseFolder.data.id); expectedFolder.id = actualResponseFolder.data.id; // Assert expectedFolder.WithDeepEqual(actualResponseFolderGet.data) .SkipDefault <DateTime>() .IgnoreDestinationProperty(x => x.dateCreated) .Assert(); }
public async Task UpdateFolder(int userId, UpdateFolderDto model) { await ExecuteActionAsync($"update folders set folder_name = @Name where id = @Id ", model); }
public async Task <ActionResult <ControllerResponse <GetFolderDto> > > update(string id, UpdateFolderDto folderIn) { string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier).ToString(); var folder = await _folderService.getByIdAsync(id); if (folder.userId != userId) { throw new UnauthorizedAccessException("Folder don't belong to you"); } folder = _mapper.Map <UpdateFolderDto, Folder>(folderIn, folder); await _folderService.updateAsync(id, folder); return(Ok(new ControllerResponse <GetFolderDto> { data = _mapper.Map <GetFolderDto>(folder) })); }