public ActionResult Edit(int?id, CustomerEditContactInfo newItem)
        {
            //Validate the input
            if (!ModelState.IsValid)
            {
                //"Version1" approach is to display the "edit form" again
                return(RedirectToAction("edit", new { id = newItem.CustomerId }));
            }

            if (id.GetValueOrDefault() != newItem.CustomerId)
            {
                //this appears to be data tampering, so redirect the user away
                return(RedirectToAction("index"));
            }

            //Attempt to do the update
            var editedItem = m.CustomerEditContactInfo(newItem);

            if (editedItem == null)
            {
                //There was a problem updating the object
                //Our "version1" approach is to display the "edit form" again
                return(RedirectToAction("edit", new { id = newItem.CustomerId }));
            }
            else
            {
                //Show the details view, which will show the updated data
                return(RedirectToAction("details", new { id = newItem.CustomerId }));
            }
        }
Beispiel #2
0
        public CustomerBase CustomerEditContactInfo(CustomerEditContactInfo newItem)
        {
            //Attempt to fetch the object
            var o = ds.Customers.Find(newItem.CustomerId);

            if (o == null)
            {
                //problem - item not found
                return(null);
            }
            else
            {
                //update the object with the incoming values
                ds.Entry(o).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                //prepare and return the object
                return(mapper.Map <Customer, CustomerBase>(o));
            }
        }