コード例 #1
0
        public ActionResult Edit(int?id, CustomerEditContactInfo newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                // Our "version 1" 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 "version 1" approach is to display the "edit form" again
                return(RedirectToAction("edit", new { id = newItem.CustomerId }));
            }
            else
            {
                // Show the details view, which will have the updated data
                return(RedirectToAction("details", new { id = newItem.CustomerId }));
            }
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: tsarkarsc/bti420winter2017
        // Attention 06 - Edit customer, contact info
        public CustomerBase CustomerEditContactInfo(CustomerEditContactInfo newItem)
        {
            // Attempt to fetch the object
            var o = ds.Customers.Find(newItem.CustomerId);

            if (o == null)
            {
                // Problem - item was not found, so return
                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 <CustomerBase>(o));
            }
        }