Пример #1
0
 // ############################################################
 public Person AddPerson(Person newPerson)
 {
     // Set the identifier value to the max-plus-one of the existing identifier values
     newPerson.Id = (this.Persons.Count > 0) ? this.Persons.Max(max => max.Id) + 1 : 1;
     // Add the object
     this.Persons.Add(newPerson);
     // Save
     ctx.Session["persons"] = this.Persons;
     return newPerson;
 }
Пример #2
0
 public ActionResult Create(Person newPerson)
 {
     if (ModelState.IsValid)
     {
         // Attempt to add the new Person object
         m.AddPerson(newPerson);
         return RedirectToAction("Index");
     }
     return View();
 }
Пример #3
0
        // ############################################################
        public Person EditPerson(Person editedPerson)
        {
            // Attempt to locate the existing object by using the passed-in identifier
            var existingPerson = this.Persons.SingleOrDefault(pid => pid.Id == editedPerson.Id);

            // If located...
            if (existingPerson != null)
            {
                // Get the object's index value in the collection
                int collectionIndex = this.Persons.IndexOf(existingPerson);
                // Replace the existing object with the new object
                this.Persons[collectionIndex] = editedPerson;
                // Save
                ctx.Session["persons"] = this.Persons;
                return editedPerson;
            }
            else
            {
                return null;
            }
        }
Пример #4
0
 public ActionResult Edit(int id, Person updatedperson)
 {
     if (ModelState.IsValid)
     {
         // Attempt to update the Person object
         m.EditPerson(updatedperson);
         return RedirectToAction("Index");
     }
     return View();
 }