// M e t h o d s // C r e a t e public Fillup Create(Fillup f) { _context.Fillups.Add(f); _context.SaveChanges(); RecomputeDaysBetweenFillups(f.VehicleId); return(f); }
// D e l e t e public bool Delete(Fillup f) { Fillup fillupToDelete = GetFillupById(f.Id); if (fillupToDelete == null) { return(false); } Guid vehicleId = fillupToDelete.VehicleId; _context.Fillups.Remove(fillupToDelete); _context.SaveChanges(); RecomputeDaysBetweenFillups(vehicleId); return(true); }
// U p d a t e public Fillup Update(Fillup f) { Fillup fillupToUpdate = GetFillupById(f.Id); if (fillupToUpdate != null) { fillupToUpdate.Date = f.Date; fillupToUpdate.Gallons = f.Gallons; fillupToUpdate.Odometer = f.Odometer; fillupToUpdate.TotalCost = f.TotalCost; fillupToUpdate.TripOdometer = f.TripOdometer; fillupToUpdate.ZipCode = f.ZipCode; _context.SaveChanges(); RecomputeDaysBetweenFillups(f.VehicleId); } return(fillupToUpdate); }