public async Task <Result <GetExpenseCategoryByIdResponse> > Handle(GetExpenseCategoryByIdQuery query, CancellationToken cancellationToken) { var expenseCategory = await _repository.GetByIdAsync(query.Id); var mappedExpenseCategory = _mapper.Map <GetExpenseCategoryByIdResponse>(expenseCategory); return(Result <GetExpenseCategoryByIdResponse> .Success(mappedExpenseCategory)); }
public async Task <Result <int> > Handle(DeleteExpenseCategoryCommand command, CancellationToken cancellationToken) { var expenseCategory = await _repository.GetByIdAsync(command.Id); await _repository.DeleteAsync(expenseCategory); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(expenseCategory.Id)); }
public async Task <Response <int> > Handle(DeleteExpenseCategoryCommand request, CancellationToken cancellationToken) { var category = await _categoryRepository.GetByIdAsync(request.Id); if (category == null) { throw new ApiException("Category not Found."); } await _categoryRepository.DeleteAsync(category); await _unitOfWork.Commit(cancellationToken); return(new Response <int>(category.Id)); }
public async Task <Result <int> > Handle(UpdateExpenseCategoryCommand command, CancellationToken cancellationToken) { var expenseCategory = await _repository.GetByIdAsync(command.Id); if (expenseCategory == null) { return(Result <int> .Fail($"Product Not Found.")); } else { expenseCategory.Name = command.Name ?? expenseCategory.Name; expenseCategory.Code = command.Code ?? expenseCategory.Code; await _repository.UpdateAsync(expenseCategory); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(expenseCategory.Id)); } }
public async Task <ExpenseCategory> GetByIdAsync(int categoryId) { var entity = await _repository.GetByIdAsync(categoryId); return(_mapper.Map <ExpenseCategory>(entity)); }