예제 #1
0
        public ActionResult New(string licensePlate, FormCollection form)
        {
            Car        car        = CarRepository.RetrieveByLicensePlate(licensePlate);
            Refuelling refuelling = null;

            try
            {
                refuelling     = new Refuelling();
                refuelling.Car = car;

                this.UpdateModel(refuelling, new[] { "Date", "ServiceStation", "Kilometers", "Liters", "PricePerLiter", "Total", "Usage" });

                RefuellingRepository.Add(refuelling);

                return(RedirectToAction("List", new { licensePlate = licensePlate }));
            }
            catch (RuleViolationException)
            {
                List <Refuelling> refuellings = RefuellingRepository.List(car);
                refuellings.Reverse();

                this.UpdateModelStateWithViolations(refuelling, ViewData.ModelState);

                var viewData = new NewRefuellingViewData
                {
                    Car            = car,
                    LastRefuelling = refuellings.Count > 0 ? refuellings[0] : null,
                    NewRefuelling  = refuelling
                };

                return(View("New", viewData));
            }
        }
        public void Update(Refuelling refuelling)
        {
            refuelling.EnsureValid();

            DataSource.DataContext.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, refuelling);
            DataSource.DataContext.SubmitChanges();
        }
        public void Add(Refuelling refuelling)
        {
            refuelling.EnsureValid();

            DataSource.DataContext.Refuellings.InsertOnSubmit(refuelling);
            DataSource.DataContext.SubmitChanges();
        }
예제 #4
0
        public ActionResult Remove(Guid id)
        {
            Refuelling refuelling = RefuellingRepository.RetrieveById(id);
            Car        car        = refuelling.Car;

            RefuellingRepository.Remove(refuelling);

            return(RedirectToAction("List", new { licensePlate = car.LicensePlate }));
        }
예제 #5
0
        public ActionResult New(string licensePlate)
        {
            Car car = CarRepository.RetrieveByLicensePlate(licensePlate);
            List <Refuelling> refuellings = RefuellingRepository.List(car);

            refuellings.Reverse();

            Refuelling refuelling = new Refuelling();

            refuelling.Date = DateTime.Now;

            var viewData = new NewRefuellingViewData
            {
                Car            = car,
                LastRefuelling = refuellings.Count > 0 ? refuellings[0] : null,
                NewRefuelling  = refuelling
            };

            return(View("New", viewData));
        }
 public void Remove(Refuelling refuelling)
 {
     DataStore.Refuellings.Remove(refuelling);
 }
 public void Update(Refuelling refuelling)
 {
     refuelling.EnsureValid();
 }
        public void Add(Refuelling refuelling)
        {
            refuelling.EnsureValid();

            DataStore.Refuellings.Add(refuelling);
        }
 public void Remove(Refuelling refuelling)
 {
     DataSource.DataContext.Refuellings.DeleteOnSubmit(refuelling);
     DataSource.DataContext.SubmitChanges();
 }