示例#1
0
        public ActionResult Edit()
        {
            HallsEditVM model = new HallsEditVM();
            TryUpdateModel(model);
            HallRepository hallRep = new HallRepository();

            if (!ModelState.IsValid)
            {
                model.Locations = GetLocations();
                return View(model);
            }

            Hall hall;
            if (model.ID==0)
            {
                hall = new Hall();
            }
            else
            {
                hall = hallRep.GetByID(model.ID);
                if (hall==null)
                {
                    return RedirectToAction("List");
                }
            }
            hall.ID = model.ID;
            hall.Name = model.Name;
            hall.LocationID = model.LocationID;

            hallRep.Save(hall);

            return RedirectToAction("List");
        }
示例#2
0
        public ActionResult Edit(int? id)
        {
            Hall hall;
            HallRepository hallRep = new HallRepository();

            if (!id.HasValue)
            {
                hall = new Hall();
            }
            else
            {
                hall = hallRep.GetByID(id.Value);
                if (hall==null)
                {
                    return RedirectToAction("List");
                }
            }
            HallsEditVM model = new HallsEditVM();
            model.ID = hall.ID;
            model.Name = hall.Name;
            model.LocationID = hall.LocationID;
            model.Locations = GetLocations();

            return View(model);
        }