Пример #1
0
        // GET: Showrooms/ManageCars/5
        public ActionResult ManageCars(int id)
        {
            //// CALL STORED PROCEDURE
            //using (var conn = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-CarStore-20170928080302.mdf;Initial Catalog=aspnet-CarStore-20170928080302;Integrated Security=True"))
            //using (var command = new SqlCommand("AddCarType", conn)
            //{
            //    CommandType = CommandType.StoredProcedure
            //})
            //{
            //    conn.Open();
            //    command.ExecuteNonQuery();
            //}

            var showroom = db.Showrooms.Find(id);

            var cars = db.Cars.Where(c => c.ShowroomId == id).ToList();

            if (showroom == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ManagerCarsViewModel()
            {
                Showroom = showroom,
                Cars     = cars
            };

            return(View(viewModel));
        }
Пример #2
0
        public ActionResult SaveManageCars(ManagerCarsViewModel viewModel)
        {
            var cars = viewModel.Cars;

            foreach (var car in cars)
            {
                var currentCar = db.Cars.SingleOrDefault(c => c.Id == car.Id);

                if (currentCar == null)
                {
                    return(HttpNotFound());
                }

                currentCar.ShowroomId = viewModel.Showroom.Id;
            }

            db.SaveChanges();

            //return View("Index");
            return(RedirectToAction("Index"));
        }