public async Task <ActionResult> DeleteFileAsync(ObjectIdRequest request)
        {
            var userId = Tools.AuthenticationManager.GetUserId(User);

            #region Get file from db
            DatabaseModule.Entities.File file;
            try
            {
                file = await _filesRepository.FindByIdAsync(request.Id);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(BadRequest("File not found"));
            }
            #endregion

            if (!FileFolderManager.CanDeleteFile(userId, file))
            {
                return(BadRequest("You can't delete file or it doesn't exist"));
            }

            #region Get bucket from db
            DatabaseModule.Entities.Bucket bucket;
            try
            {
                bucket = await _bucketsRepository.FindByIdAsync(file.BucketId.ToString());
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(BadRequest("Bucket not found"));
            }
            #endregion


            var serviceConfig        = bucket.BucketConfigData;
            var googleBucketUploader = new RequestHandlerGoogleBucket(serviceConfig.ConfigData, serviceConfig.SelectedBucket);
            var result = googleBucketUploader.DeleteFile(request.Id);

            if (!result)
            {
                return(BadRequest("Error while deleting your file"));
            }

            #region Delete file from db
            try
            {
                await _filesRepository.DeleteByIdAsync(request.Id);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(BadRequest("Deletion file from db failed"));
            }
            #endregion

            return(Ok());
        }
示例#2
0
        public async Task <ActionResult> Delete(string storyID)
        {
            _logger.LogInformation($"Delete story {storyID}");

            await _storyRepository.DeleteByIdAsync(storyID);

            return(Ok());
        }
示例#3
0
        public async Task DeleteExercise(string id, ExerciseDefinition definiton)
        {
            await _exerciseContext.DeleteByIdAsync(id);

            // Remove exercise from definition history
            definiton.History.Remove(id);
            await _exerciseDefinitionContext.ReplaceOneAsync(definiton);
        }
示例#4
0
        public async Task <Response <string> > Handle(DeleteElectricMetterCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInfo($"DeleteDeviceHandler(Id:{request.Id})");

            await _repository.DeleteByIdAsync(request.Id);

            return(new Response <string> {
                Data = request.Id, ErrorMessage = string.Empty
            });
        }
        public async Task DeleteAsync(long id)
        {
            var livroBase = await GetByIdAsync(id);

            if (livroBase == null)
            {
                throw new Exception("Não é possivel deletar o livro, o livro não está cadastrado");
            }

            await _livroRepository.DeleteByIdAsync(id);
        }
示例#6
0
        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);
        }
示例#7
0
        public async Task DeleteUser(User user)
        {
            // Clean up associated user data
            foreach (var definitionId in user.Exercises)
            {
                var definiton = await _exerciseDefinitionContext.FindByIdAsync(definitionId);

                foreach (var exerciseId in definiton.History)
                {
                    // Remove all associated exercise sesssions
                    await _exerciseContext.DeleteByIdAsync(exerciseId);
                }
                // Remove all associated exercise definitions
                await _exerciseDefinitionContext.DeleteByIdAsync(definitionId);
            }

            await _userContext.DeleteByIdAsync(user.Id);
        }
示例#8
0
        public async Task <Result <long> > DeleteByIdAsync(string id, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(new Result <long>(0, HttpStatusCode.BadRequest, problemTittle: "Id cannot be null or empty"));
            }

            long affected;

            try
            {
                affected = await _repositoryBase.DeleteByIdAsync(id, cancellationToken);
            }
            catch (Exception)
            {
                return(new Result <long>(0, HttpStatusCode.InternalServerError, problemTittle: $"Error on delete object {typeof(TEntity).Name}."));
            }

            return(new Result <long>(affected, HttpStatusCode.OK));
        }
        public async Task <IResult <bool> > Handle(DeleteAuthorCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Deleting author ...");

            try
            {
                Author author = await _authorRepository.FindByIdAsync(request.Id);

                if (author == null)
                {
                    throw new Exception("Error : Author Id does not exist.");
                }

                await _authorRepository.DeleteByIdAsync(author.Id.ToString());

                return(await Result <bool> .SuccessAsync(true));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error when Deleting author", ex);
                throw;
            }
        }
示例#10
0
 public async Task DeleteTicketAsync(Guid ticketId)
 {
     await _mongoRepository.DeleteByIdAsync(ticketId);
 }
示例#11
0
        protected override async Task <EmptyResponse> DoExecute(CommentDeleteContract message, ConsumeContext <CommentDeleteContract> context)
        {
            await _repository.DeleteByIdAsync(message.ToDelete.Id.Value);

            return(new EmptyResponse());
        }
示例#12
0
        public Task <bool> DeleteAsync(string todoId)
        {
            var check = _todoRepository.DeleteByIdAsync(todoId).IsCompleted;

            return(Task.FromResult(check));
        }
        public async Task <IActionResult> Delete(string id)
        {
            await _repository.DeleteByIdAsync(id);

            return(NoContent());
        }
 public async Task DeleteBasketAsync(string basketId)
 {
     var basket = _basketRepository.FindById(basketId);
     await _basketRepository.DeleteByIdAsync(basketId);
 }
示例#15
0
 public async Task DeleteAsync(string postId)
 {
     await _mongoRepository.DeleteByIdAsync(postId);
 }