Inheritance: ManufacturerAdd
Example #1
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));

                /*
                 * // Prepare the object to be returned
                 * var editedItem = new ManufacturerBase();
                 * editedItem.Id = fetchedObject.Id;
                 * editedItem.Name = fetchedObject.Name;
                 * editedItem.Country = fetchedObject.Country;
                 * editedItem.YearStarted = fetchedObject.YearStarted;
                 *
                 * // Return the result
                 * return editedItem;
                 */
            }
        }
Example #2
0
 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"));
     }
 }
Example #3
0
        // ############################################################

        //
        // 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));
            }
        }
Example #4
0
        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)
                {
                    return(RedirectToAction("index"));
                }
                else
                {
                    return(RedirectToAction("details", new { id = editedItem.Id }));
                }
            }
            else
            {
                return(RedirectToAction("index"));
            }
        }
        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)
                {
                    return RedirectToAction("index");
                }
                else
                {
                    return RedirectToAction("details", new { id = editedItem.Id });
                }
            }
            else
            {
                return RedirectToAction("index");
            }
        }
        // ############################################################
        // 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);

                /*
                // Prepare the object to be returned
                var editedItem = new ManufacturerBase();
                editedItem.Id = fetchedObject.Id;
                editedItem.Name = fetchedObject.Name;
                editedItem.Country = fetchedObject.Country;
                editedItem.YearStarted = fetchedObject.YearStarted;

                // Return the result
                return editedItem;
                */
            }
        }