예제 #1
0
        public ActionResult Edit(int?id, EmployeeEditContactInfo newItem)
        {
            if (!ModelState.IsValid)
            {
                // Our "version 1" approach is to display the "edit form" again
                return(RedirectToAction("edit", new { id = newItem.EmployeeId }));
            }

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

            // Attempt to do the update
            var editedItem = m.EmployeeEditContactInfo(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.EmployeeId }));
            }
            else
            {
                // Show the details view, which will have the updated data
                return(RedirectToAction("details", new { id = newItem.EmployeeId }));
            }
        }
예제 #2
0
        public ActionResult Delete(int?id, EmployeeEditContactInfo newItem)
        {
            var result = m.EmployeeDelete(id.GetValueOrDefault());

            // "result" will be true or false
            // We probably won't do much with the result, because
            // we don't want to leak info about the delete attempt

            // In the end, we should just redirect to the list view
            return(RedirectToAction("index"));
        }
예제 #3
0
        public EmployeeBase EmployeeEditContactInfo(EmployeeEditContactInfo newItem)
        {
            var o = ds.Employees.Find(newItem.EmployeeId);

            if (o == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(o).CurrentValues.SetValues(newItem);
                ds.SaveChanges();
                return(mapper.Map <Employee, EmployeeBase>(o));
            }
        }
예제 #4
0
        // Attention 06 - Edit Employee, contact info
        public EmployeeBase EmployeeEditContactInfo(EmployeeEditContactInfo newItem)
        {
            // Attempt to fetch the object
            var o = ds.Employees.Find(newItem.EmployeeId);

            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 <Employee, EmployeeBase>(o));
            }
        }
예제 #5
0
        public ActionResult Edit(int?id, EmployeeEditContactInfo newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("edit", new { id = newItem.EmployeeId }));
            }

            if (id.GetValueOrDefault() != newItem.EmployeeId)
            {
                return(RedirectToAction("index"));
            }

            var editedItem = m.EmployeeEditContactInfo(newItem);

            if (editedItem == null)
            {
                return(RedirectToAction("edit", new { id = newItem.EmployeeId }));
            }
            else
            {
                return(RedirectToAction("details", new { id = newItem.EmployeeId }));
            }
        }