Пример #1
0
        //   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);
        }
Пример #2
0
        //   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);
        }
Пример #3
0
        //   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);
        }