public async Task <ActionResult <TruckCargo> > PostTruckCargo(TruckCargo truckCargo) { _context.TruckCargo.Add(truckCargo); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTruckCargo", new { id = truckCargo.Id }, truckCargo)); }
public async Task <IActionResult> PutTruckCargo(int id, TruckCargo truckCargo) { if (id != truckCargo.Id) { return(BadRequest()); } _context.Entry(truckCargo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TruckCargoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } TruckCargo = await _context.TruckCargo.FirstOrDefaultAsync(m => m.Id == id); if (TruckCargo == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TruckCargo = await _context.TruckCargo.FindAsync(id); if (TruckCargo != null) { _context.TruckCargo.Remove(TruckCargo); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task OnGetAsync() { TruckCargo = await _context.TruckCargo.ToListAsync(); foreach (var cargo in TruckCargo) { if (cargo.TcargoCount == 0) { WeightHandling = "ERROR: No cargo!"; } else if (cargo.TcargoWeight <= 0 || cargo.TcargoWeight > 500) { TotalWeight = (decimal)(TotalWeight + cargo.TcargoWeight); WeightHandling = "ERROR: At least one item has a strange weight"; } else { TotalWeight = (decimal)(TotalWeight + (cargo.TcargoWeight * cargo.TcargoCount)); } } NextDestination = TruckCargo.Any() ? TruckCargo[0].TcargoDestination : "Home"; Button = "Dispatch!"; if (TotalWeight > 500) { ErrorHandling = "ERROR: Truck has too much load"; CurrentLocation = "Home"; Moving = "Stopped"; } else if (TotalWeight < 0) { ErrorHandling = "ERROR: Truck has negative load"; CurrentLocation = "Home"; Moving = "Stopped"; } else if (!TruckCargo.Any()) { CurrentLocation = "Home"; Button = "Dispatch!"; Moving = "Stopped"; } else { ErrorHandling = "Good to go!"; string[] gps = new string[] { "Tallinn", "Tartu", "Pärnu", "Viljandi", "Rapla", "Haapsalu", "Valga", "Seal", "Siin", "Iganurgapeal", "Jõgeva", "Home", "Home", "Home", "Home", "Home", "Home" }; while (CurrentLocation != NextDestination) { Button = "Check"; Random rnd = new Random(); int random = rnd.Next(0, 16); CurrentLocation = gps[random]; if (CurrentLocation == "Siin" || CurrentLocation == "Seal" || CurrentLocation == "Iganurgapeal") { Moving = "WRONG WAY!"; break; } else if (CurrentLocation == NextDestination) { Moving = "Stopped"; break; } else if (CurrentLocation == "Home") { Button = "Dispatch!"; Moving = "Stopped"; break; } else { Moving = "Driving!"; break; } } } }