Пример #1
0
        // GET: People/Create
        public ActionResult Create()
        {
            EditOrCreatePersonViewModel model = new EditOrCreatePersonViewModel()
            {
                Cities = new SelectList(db.Cities, "Id", "Name")
            };

            return(View(model));
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "Id,Name,CityId")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            EditOrCreatePersonViewModel model = new EditOrCreatePersonViewModel()
            {
                Person = person,
                Cities = new SelectList(db.Cities, "Id", "Name")
            };

            return(View(person));
        }
Пример #3
0
        public ActionResult Edit([Bind(Include = "Id,Name,CityId")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Entry(person).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            EditOrCreatePersonViewModel model = new EditOrCreatePersonViewModel()
            {
                Person = person,
                Cities = new SelectList(db.Cities, "Id", "Name")
            };

            return(View(model));
        }
Пример #4
0
        // GET: People/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Person person = db.People.Find(id);

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

            EditOrCreatePersonViewModel model = new EditOrCreatePersonViewModel()
            {
                Person = person,
                Cities = new SelectList(db.Cities, "Id", "Name")
            };

            return(View(model));
        }