コード例 #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));
            }
        }
コード例 #2
0
        public void Update(Refuelling refuelling)
        {
            refuelling.EnsureValid();

            DataSource.DataContext.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, refuelling);
            DataSource.DataContext.SubmitChanges();
        }
コード例 #3
0
        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));
        }
コード例 #6
0
 public void Remove(Refuelling refuelling)
 {
     DataStore.Refuellings.Remove(refuelling);
 }
コード例 #7
0
 public void Update(Refuelling refuelling)
 {
     refuelling.EnsureValid();
 }
コード例 #8
0
        public void Add(Refuelling refuelling)
        {
            refuelling.EnsureValid();

            DataStore.Refuellings.Add(refuelling);
        }
コード例 #9
0
 public void Remove(Refuelling refuelling)
 {
     DataSource.DataContext.Refuellings.DeleteOnSubmit(refuelling);
     DataSource.DataContext.SubmitChanges();
 }