Exemple #1
0
        public ActionResult PersonForm(int id, PersonFormDto personFormDto)
        {
            if (ModelState.IsValid)
            {
                bool isNew = id == 0;
                if (isNew)
                {
                    // make model object from the dto
                    var person = personFormDto.ToModel();

                    // add to db
                    _people.Add(person);
                }
                else
                {
                    // fetch from db
                    var person = _people.Find(id);

                    // update with dto values
                    personFormDto.UpdateModel(person);

                    _people.Update(person);
                }

                _people.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(PartialView(personFormDto));
        }
        public ActionResult PersonForm(int id, PersonFormDto personFormDto)
        {
            if (ModelState.IsValid)
            {
                bool isNew = id == 0;
                if (isNew)
                {
                    // make model object from the dto
                    var person = personFormDto.ToModel();

                    // add to db
                    _people.Add(person);
                }
                else
                {
                    // fetch from db
                    var person = _people.Find(id);

                    // update with dto values
                    personFormDto.UpdateModel(person);

                     _people.Update(person);
                }

                _people.SaveChanges();
                return RedirectToAction("Index");
            }
            return PartialView(personFormDto);
        }
Exemple #3
0
        public ActionResult PersonForm(int?id)
        {
            Person person        = id.HasValue ? _people.Find(id.Value) : new Person();
            var    personFormDto = new PersonFormDto().FromModel(person);

            return(PartialView(personFormDto));
        }
 public ActionResult PersonForm(int? id)
 {
     Person person = id.HasValue ? _people.Find(id.Value) : new Person();
     var personFormDto = new PersonFormDto().FromModel(person);
     return PartialView(personFormDto);
 }