public async Task UpdateAsync(ExpenseCategoryToUpdate model)
        {
            var entity = await _repository.GetByIdAsync(model.Id);

            _mapper.Map(model, entity);

            await _repository.UpdateAsync(entity);
        }
Exemple #2
0
            public async Task <Response <int> > Handle(UpdateExpenseCategoryCommand request, CancellationToken cancellationToken)
            {
                var category = await _categoryRepository.GetByIdAsync(request.Id);

                if (category == null)
                {
                    throw new ApiException("Category not Found.");
                }
                else
                {
                    category.Name = request.Name;
                    category.Code = request.Code;

                    await _categoryRepository.UpdateAsync(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));
                }
            }