Example #1
0
        public async Task <ActionResult <ExpenseDto> > DeleteExpense(long id)
        {
            try
            {
                var expense = await _repository.DetailAsync(id);

                if (expense == null)
                {
                    _logger.LogInfo($"{nameof(DeleteExpense)}({id}) : return NotFound from database");
                    return(NotFound());
                }

                await _repository.DeleteAsync(expense);

                var expenseDto = _mapper.Map <ExpenseDto>(expense);

                _logger.LogInfo($"{nameof(DeleteExpense)}({id}) : return Ok from database");
                return(Ok(expenseDto));
            }
            catch (Exception ex)
            {
                _logger.LogError($"{nameof(DeleteExpense)}({id}) : something went wrong{Environment.NewLine}" +
                                 $"\t{ex.Message}");
                throw;
            }
        }
        public async Task <IActionResult> DeleteExpense(int id)
        {
            if (await _expenseRepository.DeleteAsync(id))
            {
                await _expenseRepository.SaveAsync();

                return(Ok("Expense deleted"));
            }
            return(BadRequest());
        }
        public async Task <ExpenseModel> Handle(DeleteExpenseRequest request, CancellationToken cancellationToken)
        {
            var dto = await fExpenseRepository.DeleteAsync(request.Id, cancellationToken);

            if (dto is null)
            {
                throw new NotFoundCodeException(request.Id, "Expense");
            }

            return(fMapper.Map <ExpenseDto, ExpenseModel>(dto));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            if (await _expenseRepository.DeleteAsync(id))
            {
                await _expenseRepository.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction(nameof(Delete), id));
        }
Example #5
0
        public async Task DeleteExpenseAsync(Guid id)
        {
            if (!_expenseRepository.IsExpenseExist(id))
            {
                throw new ServiceExceptions(ServiceErrorCodes.ExpenseNotExist,
                                            "Expense object not exist");
            }

            var expense = await _expenseRepository.GetAsync(id);

            await _expenseRepository.DeleteAsync(expense);
        }
        public async Task <bool> DeleteExpenseByIdAsync(int id)
        {
            var review = await _expenseRepository.ListAsync(e => e.Id == id);

            if (review != null)
            {
                await _expenseRepository.DeleteAsync(review.First());

                return(true);
            }

            return(false);
        }
Example #7
0
        public async Task <bool> DeleteAsync(long id)
        {
            _unitOfWork.BeginTransaction();
            var deleted = await _repository.DeleteAsync(id);

            if (!deleted)
            {
                return(false);
            }

            var result = await _unitOfWork.CommitAsync();

            return(result > 0);
        }
Example #8
0
 public async Task DeleteExpense(Guid id)
 {
     await _repository.DeleteAsync(id);
 }