public ActionResult Create(PersonAdd newItem)
        {
            // Handles HTTP POST, and adds the new person, then redirects to another view
            // Notice that this method is prefixed with an "attribute", [HttpPost]

            // Check that the incoming data is valid
            if (ModelState.IsValid)
            {
                var addedItem = m.AddPerson(newItem);
            }
            else
            {
                // Return the object so the user can edit it correctly
                return(View(newItem));
            }

            // If the incoming data is valid and the new data was added, redirect
            return(RedirectToAction("index"));
        }
        public ActionResult Create(PersonAdd newItem)
        {
            // Handles HTTP POST, and adds the new person, then redirects to another view
            // Notice that this method is prefixed with an "attribute", [HttpPost]

            // Check that the incoming data is valid
            if (ModelState.IsValid)
            {
                var addedItem = m.AddPerson(newItem);
            }
            else
            {
                // Return the object so the user can edit it correctly
                return View(newItem);
            }

            // If the incoming data is valid and the new data was added, redirect
            return RedirectToAction("index");
        }
Esempio n. 3
0
        // Add a new person
        public PersonFull AddPerson(PersonAdd newItem)
        {
            // Calculate the next value for the identifier
            int newId = (persons.Count > 0) ? newId = persons.Max(id => id.Id) + 1 : 1;

            // Create a new item; notice the property mapping
            var addedItem = new PersonFull
            {
                Id = newId,
                FirstName = newItem.FirstName,
                LastName = newItem.LastName,
                Age = newItem.Age
            };

            // Add the new item to the store
            persons.Add(addedItem);

            // Return the new item
            return addedItem;
        }
Esempio n. 4
0
        // Add a new person
        public PersonFull AddPerson(PersonAdd newItem)
        {
            // Calculate the next value for the identifier
            int newId = (persons.Count > 0) ? newId = persons.Max(id => id.Id) + 1 : 1;

            // Create a new item; notice the property mapping
            var addedItem = new PersonFull
            {
                Id        = newId,
                FirstName = newItem.FirstName,
                LastName  = newItem.LastName,
                Age       = newItem.Age
            };

            // Add the new item to the store
            persons.Add(addedItem);

            // Return the new item
            return(addedItem);
        }