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."); }
private async Task SimulatePetrolStationWorkCycle(Entities.PetrolStation petrolStation) { petrolStation.ChangeCurrentBusinessDate(minute_interval); petrolStation.SimulateActivity(); var orders = petrolStation.GetOrders(); petrolStation.ChangeCurrentBusinessDate(minute_interval); var supplies = SupplyFactory.CreateFor(orders, petrolStation.CurrentDateTime); petrolStation.RefuelTanks(supplies); await repository.UpdateAsync(petrolStation); await SendEvents(petrolStation); }