public async Task <ActionResult> SwitchFavouriteFolder(FavouriteSwitch favouriteSwitch) { var userId = Tools.AuthenticationManager.GetUserId(User); if (!await FileFolderManager.CanDeleteFolder(userId, new ObjectId(favouriteSwitch.Id), _foldersRepository)) { return(BadRequest("You don't have access to folder or it doesn't exist")); } await _foldersRepository.UpdateOneAsync(favouriteSwitch.Id, "Favourite", favouriteSwitch.IsFavourite); return(Ok()); }
public async Task <ActionResult> DeleteFolder(DTO.Request.ObjectIdRequest request) { var userId = AuthenticationManager.GetUserId(User); if (!await FileFolderManager.CanDeleteFolder(userId, new ObjectId(request.Id), _foldersRepository)) { return(BadRequest("You don't have right to delete folder, or it doesn't exist")); } var foldersTree = await FileFolderManager.GetFolderTree(new ObjectId(request.Id), _foldersRepository); var buckets = (await _bucketsRepository.FilterByAsync(bucket => bucket.OwnerId == null || bucket.OwnerId == userId)).ToList(); var files = (await _filesRepository.FilterByAsync(file => foldersTree.Contains(file.FolderId))).ToList(); if (files.Count() != 0) { foreach (var file in files) { var bucket = buckets.First(b => b.Id == file.BucketId); var serviceConfig = bucket.BucketConfigData; var googleBucketUploader = new RequestHandlerGoogleBucket(serviceConfig.ConfigData, serviceConfig.SelectedBucket); var result = googleBucketUploader.DeleteFile(file.Id.ToString()); if (!result) { _logger.LogError("Error while deleting file " + file.Id + " during deletion folder " + request.Id); } } var filesIds = files.Select(f_ => f_.Id); await _filesRepository.DeleteManyAsync(f => filesIds.Contains(f.Id)); } await _foldersRepository.DeleteManyAsync(folder => foldersTree.Contains(folder.Id)); return(Ok()); }