Exemplo n.º 1
0
        public ActionResult Edit(int?id, CustomerEditContactViewModel model)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", new { id = model.CustomerId }));
            }
            if (id.GetValueOrDefault() != model.CustomerId)
            {
                // This appears to be data tampering, so redirect the user away
                return(RedirectToAction("Index"));
            }
            // Attempt to do the update
            var editedItem = m.CustomerEditContactInfo(model);

            if (editedItem == null)
            {
                return(RedirectToAction("Edit", new { id = model.CustomerId }));
            }
            else
            {
                // Show the details view, which will show the updated data
                return(RedirectToAction("Details", new { id = model.CustomerId }));
            }
        }
Exemplo n.º 2
0
        public CustomerBaseViewModel CustomerEditContactInfo(CustomerEditContactViewModel customer)
        {
            // Attempt to fetch the object.
            var obj = ds.Customers.Find(customer.CustomerId);

            if (obj == null)
            {
                // Customer was not found, return null.
                return(null);
            }
            else
            {
                // Customer was found. Update the entity object
                // with the incoming values then save the changes.
                ds.Entry(obj).CurrentValues.SetValues(customer);
                ds.SaveChanges();
                // Prepare and return the object.
                return(mapper.Map <Customer, CustomerBaseViewModel>(obj));
            }
        }