public async Task Handle(V1.AccountClosed @event, CancellationToken cancellationToken) { var accountDto = await accountDtoRepository.GetAccountByAccountId(@event.AccountId); if (accountDto == null) { throw new NullReferenceException("No accountDto has been found"); } accountDto.MonthIsClosed = true; await accountDtoRepository.Update(accountDto); }
public async Task Handle(V1.BookingAddedToAccount @event, CancellationToken cancellationToken) { var accountDto = await accountDtoRepository.GetAccountByAccountId(@event.AccountId); if (accountDto == null) { throw new NullReferenceException("No accountDto has been found"); } if (accountDto.Items == null) { accountDto.Items = new List <AccountItemDto>(); } accountDto.Items.Add(new AccountItemDto(@event.BookingId, @event.Date, @event.Amount, @event.Description)); accountDto.TotalSpent = accountDto.Items.Sum(x => x.Amount); await accountDtoRepository.Update(accountDto); }
public async Task Handle(V1.BookingRemovedFromAccount @event, CancellationToken cancellationToken) { var accountDto = await accountDtoRepository.GetAccountByAccountId(@event.AccountId); if (accountDto == null) { throw new NullReferenceException("No accountDto has been found"); } if (accountDto.Items == null) { accountDto.Items = new List <AccountItemDto>(); } var bookingItem = accountDto.Items.Single(x => x.BookingId == @event.BookingId); accountDto.Items.Remove(bookingItem); accountDto.TotalSpent = accountDto.Items.Sum(x => x.Amount); await accountDtoRepository.Update(accountDto); }