public async Task <ApiResult <DeleteResult> > Delete([FromRoute] string id) { var objectId = ParseCertId(id); var deleteCourseResult = await _repository.DeleteManyAsync <Course>(CourseController.CollectionName, x => x.CertificationId == id); return(await _repository.DeleteAsync <Certification>(CollectionName, x => x.Id == objectId)); }
public async Task DeleteDefinition(ExerciseDefinition definition) { await _exerciseDefinitionContext.DeleteByIdAsync(definition.Id); // Remove definition from user exercises User user = await _userContext.FindByIdAsync(definition.User); user.Exercises.Remove(definition.Id); await _userContext.ReplaceOneAsync(user); // Remove exercises associated with definition await _exerciseContext.DeleteManyAsync(e => e.Definition == definition.Id); }
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()); }