示例#1
0
        public ViewResult Edit(int productId)
        {
            SportNutrition product = repository.Products
                                     .FirstOrDefault(p => p.SportNutritionId == productId);

            return(View(product));
        }
示例#2
0
        public RedirectToRouteResult RemoveFromCart(Cart cart, int nutritionId, string returnUrl)
        {
            SportNutrition product = repository.Products
                                     .FirstOrDefault(p => p.SportNutritionId == nutritionId);

            if (product != null)
            {
                cart.RemoveLine(product);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
示例#3
0
        public ActionResult Delete(int productId)
        {
            SportNutrition deletedProduct = repository.DeleteProduct(productId);

            if (deletedProduct != null)
            {
                TempData["message"] = string.Format("{0} was deleted",
                                                    deletedProduct.Name);
            }
            return(RedirectToAction("Index"));
        }
示例#4
0
        public SportNutrition DeleteProduct(int productID)
        {
            SportNutrition dbEntry = context.Products.Find(productID);

            if (dbEntry != null)
            {
                context.Products.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
示例#5
0
 public ActionResult Edit(SportNutrition product, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.Name);
         return(RedirectToAction("Index"));
     }
     else
     {
         // there is something wrong with the data values
         return(View(product));
     }
 }
示例#6
0
 public void SaveProduct(SportNutrition product)
 {
     if (product.SportNutritionId == 0)
     {
         context.Products.Add(product);
     }
     else
     {
         SportNutrition dbEntry = context.Products.Find(product.SportNutritionId);
         if (dbEntry != null)
         {
             dbEntry.Name        = product.Name;
             dbEntry.Description = product.Description;
             dbEntry.Price       = product.Price;
             dbEntry.Category    = product.Category;
             dbEntry.ImageName   = product.ImageName;
         }
     }
     context.SaveChanges();
 }
示例#7
0
 public void SaveProduct(SportNutrition product)
 {
     throw new NotImplementedException();
 }