Пример #1
0
        public void UpdateCar(Car car)
        {
            var carToUpdate = _cars.FirstOrDefault(c => c.Id == car.Id);

            if (carToUpdate == null) return;

            carToUpdate.Negociable = car.Negociable;
            carToUpdate.Annee = car.Annee;
            carToUpdate.Conditions = car.Conditions;
            carToUpdate.Information = car.Information;
            carToUpdate.Marque = car.Marque;
            carToUpdate.Modele = car.Modele;
            carToUpdate.Proprietaire = car.Proprietaire;
            carToUpdate.Telephone = car.Telephone;
            carToUpdate.TitreAnnonce = car.TitreAnnonce;
            carToUpdate.Prix = car.Prix;
        }
Пример #2
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Car car = new Car();

                TryUpdateModel(car, collection);

                if (!ModelState.IsValid) return View();

                _carRepository.AddCar(car);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #3
0
        private void Init()
        {
            Car corvette = new Car
            {
                Id = GetNextCarId(),
                TitreAnnonce = "Belle Corvette en exellent état!",
                Annee = 2002,
                Conditions = true,
                Information = "Bacon ipsum dolor amet flank hamburger venison jowl kielbasa. Kielbasa short loin turducken biltong t-bone pork loin corned beef kevin leberkas beef jerky capicola bacon landjaeger. Biltong ham hock brisket jowl pork belly. Sirloin kevin turkey jowl bresaola meatloaf cupim. Flank tenderloin pig prosciutto jerky fatback.",
                Marque = "Chevrolet",
                Modele = "Corvette",
                Negociable = false,
                Prix = new decimal(50000),
                Proprietaire = "Raphaël Doré",
                Telephone = "418-222-2222"
            };

            _cars.Add(corvette);
        }
Пример #4
0
 public void AddCar(Car car)
 {
     _cars.Add(car);
 }
Пример #5
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {

                if (_carRepository.GetCar(id) == null) return RedirectToAction("Index");

                Car car = new Car();

                TryUpdateModel(car, collection);

                if (!ModelState.IsValid) return View(_carRepository.GetCar(id));

                _carRepository.UpdateCar(car);

                return RedirectToAction("Index");
            }
            catch(Exception ex)
            {
                ModelState.AddModelError("", ex.Source + " - " + ex.Message);
                return View(_carRepository.GetCar(id));
            }
        }