public Task <bool> Handle(UpdateFavoredCommand command) { var entity = _favoredRepository.Get(command.Id); if (entity == null) { AddNotification("favorecido", "Favorecido não localizado"); return(Task.FromResult(false)); } entity.Update( new Name(command.Name), _favoredTypeRepository.Get(command.FavoredType) ); AddNotifications(entity); if (Invalid) { return(Task.FromResult(true)); } _favoredRepository.Update(entity); _uow.Commit(); return(Task.FromResult(true)); }
public Task <bool> Handle(RegisterNewExpenseCommand command) { var owner = _accountantRepository.Get(command.Owner); if (owner == null) { AddNotification("correntista", "Correntista não localizado"); return(Task.FromResult(false)); } var bankAccount = owner.GetAccount(command.Account); if (bankAccount == null) { AddNotification("conta-corrente", "Conta corrente não localizada"); return(Task.FromResult(false)); } var entity = new Expense( Guid.NewGuid(), bankAccount, new Description(command.Description), _favoredRepository.Get(command.Favored), new Money(command.Value) ); AddNotifications(entity); if (Invalid) { return(Task.FromResult(false)); } _expenseRepository.Create(entity); _uow.Commit(); return(Task.FromResult(true)); }