public ActionResult Create(Nutrient nutrient)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Nutrients.Add(nutrient);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Please try again and if the problem persists please contact the system administrator");
            }

            return View(nutrient);
        }
 public ActionResult Edit(Nutrient nutrient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nutrient).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(nutrient);
 }
        private void PopulateNutrientsDropDownList(Nutrient selectedNutrient)
        {
            var nutrientsQuery = from d in db.Nutrients
                                 orderby d.Name
                                 select d;

            ViewBag.NutrientID = new SelectList(nutrientsQuery, "NutrientID", "Name", selectedNutrient.NutrientID);
        }