public async Task Handle(NozzleUsed @event) { logger.LogDebug($"Nozzle used event received. Id: {@event.Id}"); var petrolStation = await repository.GetAsync(callContext.PetrolStationId.Value); petrolStation.Time = @event.TimeStamp; var tank = petrolStation.Tanks.SingleOrDefault(x => x.Nozzles.Any(z => z.Id == @event.Id)); var nozzle = tank.Nozzles.Single(z => z.Id == @event.Id); nozzle.LastTransactionVolume = @event.PetrolAmountInTransaction; nozzle.TotalPetrolAmount = @event.TotalDispatchedPetrolAmount; var report = factory.CreateReportForNozzleUsed(tank.Id, @event); if (petrolStation.Reports == null) { petrolStation.Reports = new List <PetrolStationReport>(); } petrolStation.Reports.Add(report); tank.CurrentVolume -= @event.PetrolAmountInTransaction; await repository.UpdateAsync(petrolStation); await hub.Clients.All.SendAsync("StationUpdate", petrolStation.Id); logger.LogDebug($"Nozzle used event received handling ended."); }
public PetrolStationReport CreateReportForNozzleUsed(Guid tankId, NozzleUsed @event) { return(new PetrolStationReport() { TankId = tankId, NozzleId = @event.Id, TimeStamp = @event.TimeStamp, Report = $"Nozzle was used. Petrol amount in transaction: {@event.PetrolAmountInTransaction}. Total dispatched petrol amount by nozzle: {@event.TotalDispatchedPetrolAmount}.", Status = ReportStatus.NozzleUsed }); }
private IEvent FinishUsingNozzle(DateTime currentDateTime) { TotalPetrolAmount += PetrolAmountInCurrentTransaction; IsCurrentlyInUse = false; IEvent eventToPublish; if (CurrentClient.PayForOrder()) { TotalStolenPetrolAmount += 0; LastStolenPetrolAmount = 0; eventToPublish = new NozzleUsed(Id, currentDateTime, PetrolAmountInCurrentTransaction, TotalPetrolAmount); PetrolAmountInCurrentTransaction = 0; } else { TotalStolenPetrolAmount += PetrolAmountInCurrentTransaction; LastStolenPetrolAmount = PetrolAmountInCurrentTransaction; eventToPublish = new PetrolStolenByCustomer(Id, currentDateTime, LastStolenPetrolAmount, TotalStolenPetrolAmount, TotalPetrolAmount); PetrolAmountInCurrentTransaction = 0; } return(eventToPublish); }