Ejemplo n.º 1
0
        public ActionResult EditPerson(PersonVM model)
        {
            if (ModelState.IsValid)
            {
                using (var context = new LabEntities())
                {
                    Person editedPerson = new Person
                    {
                        Id         = model.Id,
                        LastName   = model.LastName,
                        FirstName  = model.FirstName,
                        Patronymic = model.Patronymic,
                        Gender     = model.Gender,
                        Age        = model.Age,
                        HasJob     = model.HasJob
                    };
                    context.People.Attach(editedPerson);
                    context.Entry(editedPerson).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }

                return(RedirectToAction("ListOfPeople"));
            }
            ViewBag.Genders = new SelectList(GetGendersList(), "Item1", "Item2");
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(Guid personID)
        {
            using (var context = new LabEntities())
            {
                Person personToDelete = new Person
                {
                    Id = personID
                };
                context.Entry(personToDelete).State = System.Data.Entity.EntityState.Deleted;

                context.SaveChanges();
            }
            return(RedirectToAction("ListOfPeople"));
        }