Exemplo n.º 1
0
            public async Task Handle(Command request, CancellationToken cancellationToken)
            {
                int expenseCategoryId;

                if (request.Category.IsNew)
                {
                    var expenseCategory = new ExpenseCategory(request.Category.Name);
                    await _expenseCategoryRepository.AddAsync(expenseCategory);

                    await _expenseCategoryRepository.SaveChangesAsync();

                    expenseCategoryId = expenseCategory.ExpenseCategoryId;
                }
                else
                {
                    expenseCategoryId = request.Category.ExpenseCategoryId.Value;
                }

                var expense = await _expenseRepository.FindById(request.ExpenseId);

                if (!request.JustThisOne && expense.ExpenseRecipientId.HasValue)
                {
                    var expenseRecipient = await _expenseRecipientRepository.FindById(expense.ExpenseRecipientId.Value);

                    expenseRecipient.ChangeExpenseCategory(expenseCategoryId, expense.ExpenseMonth);
                    await _expenseRecipientRepository.SaveChangesAsync();
                }
                else
                {
                    expense.SetExpenseCategory(expenseCategoryId);
                    await _expenseRepository.SaveChangesAsync();
                }
            }
            public async Task <Response <int> > Handle(CreateExpenseCategoryCommand request, CancellationToken cancellationToken)
            {
                var category = _mapper.Map <ExpenseCategory>(request);
                await _categoryRepository.AddAsync(category);

                await _unitOfWork.Commit(cancellationToken);

                return(new Response <int>(category.Id));
            }
        public async Task AddAsync(ExpenseCategoryToAdd model)
        {
            var entity = _mapper.Map <ExpenseCategoryEf>(model);

            await _repository.AddAsync(entity);
        }