public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } MyFillUp.User = await _user.GetUserAsync(User); int lastOdometerReading = 0; var lastFillUp = _context.FillUp.OrderByDescending(ff => ff.Date).FirstOrDefault(f => f.Vehicle.Id == MyFillUp.Vehicle.Id); if (lastFillUp != null) { lastOdometerReading = lastFillUp.OdometerReading; } else { lastOdometerReading = MyFillUp.Vehicle.InitialOdometerReading; } MyFillUp.MileageDelta = MyFillUp.OdometerReading - lastOdometerReading; MyFillUp.MPG = (MyFillUp.MileageDelta / (MyFillUp.Litres / 4 .54)); _context.FillUp.Add(MyFillUp); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { Id = MyFillUp.Vehicle.Id })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(FillUp).State = EntityState.Modified; try { await _context.SaveChangesAsync(); RecalculateDeltasAndMPG(FillUp.Vehicle.Id); } catch (DbUpdateConcurrencyException) { if (!FillUpExists(FillUp.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return Page(); } _context.Attach(Vehicle).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VehicleExists(Vehicle.Id)) { return NotFound(); } else { throw; } } return RedirectToPage("./Index"); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Vehicle.User = await _user.GetUserAsync(User); _context.Vehicle.Add(Vehicle); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } FillUp = await _context.FillUp.FindAsync(id); if (FillUp != null) { _context.FillUp.Remove(FillUp); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Vehicle = await _context.Vehicle.FindAsync(id); if (Vehicle != null) { _context.Vehicle.Remove(Vehicle); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }