Inheritance: ManufacturerAdd
        public ActionResult Edit(int id, ManufacturerBase newItem)
        {
            // Two tests are required...
            if (ModelState.IsValid & id == newItem.Id)
            {
                // Attempt to update the item
                ManufacturerBase editedItem = m.EditManufacturer(newItem);

                if (editedItem == null)
                {
                    // There was a problem updating the object
                    return(View(newItem));
                }
                else
                {
                    // Succesful - item was edited
                    TempData["statusMessage"] = "Edits have been saved.";
                    return(RedirectToAction("details", new { id = editedItem.Id }));
                }
            }
            else
            {
                // Return the object so the user can edit it correctly
                return(View(newItem));
            }
        }
 public ActionResult Create(ManufacturerAdd newItem)
 {
     if (ModelState.IsValid)
     {
         ManufacturerBase addedItem = m.AddManufacturer(newItem);
         // Should probably do a quick if-null test
         return(RedirectToAction("details", new { id = addedItem.Id }));
     }
     else
     {
         return(RedirectToAction("index"));
     }
 }
        // ############################################################

        //
        // GET: /Manufacturers/Edit/5
        public ActionResult Edit(int id)
        {
            // Attempt to get the object with the matching identifier
            ManufacturerBase fetchedObject = m.GetManufacturerById(id);

            if (fetchedObject == null)
            {
                return(RedirectToAction("index"));
            }
            else
            {
                return(View(fetchedObject));
            }
        }
        // ############################################################

        //
        // GET: /Manufacturers/Delete/5
        public ActionResult Delete(int?id)
        {
            // The type of the parameter above was changed to int?, a nullable int
            // This will suppress an error message

            // Attempt to fetch the object to be deleted
            // Notice that we must use a method on the nullable int
            ManufacturerBase itemToDelete = m.GetManufacturerById(id.GetValueOrDefault());

            if (itemToDelete == null)
            {
                return(RedirectToAction("index"));
            }
            else
            {
                return(View(itemToDelete));
            }
        }
Example #5
0
        // ############################################################
        // Edit existing
        public ManufacturerBase EditManufacturer(ManufacturerBase newItem)
        {
            // Attempt to fetch the object with the matching identifier
            var fetchedObject = ds.Manufacturers.Find(newItem.Id);

            if (fetchedObject == null)
            {
                // Return null to the caller (who will also test the result)
                return(null);
            }
            else
            {
                // Update the object with the incoming values
                // Before doing this, we may have to perform
                // business-rule validations
                ds.Entry(fetchedObject).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                // Prepare and return the object
                return(Mapper.Map <ManufacturerBase>(fetchedObject));
            }
        }
        public ActionResult Edit(int id, ManufacturerBase newItem)
        {
            // Two tests are required...
            if (ModelState.IsValid & id == newItem.Id)
            {
                // Attempt to update the item
                ManufacturerBase editedItem = m.EditManufacturer(newItem);

                if (editedItem == null)
                {
                    // There was a problem updating the object
                    return View(newItem);
                }
                else
                {
                    // Succesful - item was edited
                    TempData["statusMessage"] = "Edits have been saved.";
                    return RedirectToAction("details", new { id = editedItem.Id });
                }
            }
            else
            {
                // Return the object so the user can edit it correctly
                return View(newItem);
            }
        }
        // ############################################################
        // Edit existing
        public ManufacturerBase EditManufacturer(ManufacturerBase newItem)
        {
            // Attempt to fetch the object with the matching identifier
            var fetchedObject = ds.Manufacturers.Find(newItem.Id);

            if (fetchedObject == null)
            {
                // Return null to the caller (who will also test the result)
                return null;
            }
            else
            {
                // Update the object with the incoming values
                // Before doing this, we may have to perform
                // business-rule validations
                ds.Entry(fetchedObject).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                // Prepare and return the object
                return Mapper.Map<ManufacturerBase>(fetchedObject);
            }
        }