public ActionResult ProductMaterial(int productId)
 {
     ManageProductBusiness mpb = new ManageProductBusiness();
     var productMaterial = mpb.GetListMaterial(productId);
     var product = mpb.GetProductDetail(productId);
     ViewBag.productName = product.ProductName;
     ViewBag.productId = product.ProductId;
     return View(productMaterial);
 }
 public ActionResult Edit(int productId)
 {
     try
     {
         User staffUser = Session["User"] as User;
         if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] == 3)
         {
             return RedirectToAction("Index", "Home");
         }
         if ((int)Session["UserRole"] == 1)
         {
             return RedirectToAction("Index", "StoreInfor");
         }
         ViewBag.TreeView = "product";
         ViewBag.TreeViewMenu = "productList";
         ManageProductBusiness mpb = new ManageProductBusiness();
         var product = mpb.GetProductDetail(productId);
         var materialList = mpb.GetListMaterial(productId);
         var category = mpb.GetCategory();
         Policy maxPricePolicy = db.Policies.SingleOrDefault(n => n.PolicyId == 2);
         int maxPrice = maxPricePolicy.PolicyBound;
         ViewBag.maxPrice = maxPrice;
         ViewBag.materialList = materialList;
         ViewBag.category = category;
         if (product == null)
         {
             return HttpNotFound();
         }
         InitiateMaterialList(productId);
         return View(product);
     }
     catch
     {
         return RedirectToAction("ManageError", "Error");
     }
 }
 public int EditConfirm(int productId, string productName, string productUnit, double productWeight, string productDes, string productNote, int productPrice, int dropCate, string fileName, int[] materialId, int[] materialQuantity)
 {
     try
     {
         ManageProductBusiness mpb = new ManageProductBusiness();
         var productToUpdate = mpb.GetProductDetail(productId);
         string productCode = CreateProductCode(productName);
         var productList = mpb.GetActiveProduct();
         if (!StringComparer.CurrentCultureIgnoreCase.Equals(productName, productToUpdate.ProductName))
         {
             for (int i = 0; i < productList.Count; i++)
             {
                 if (StringComparer.CurrentCultureIgnoreCase.Equals(productName, productList[i].ProductName))
                 {
                     //string strURL = Request.UrlReferrer.AbsolutePath;
                     //string URL = String.Format("{0}{1}{2}", strURL, "?ProductId=", productId);
                     //TempData["Error"] = String.Format("{0}{1}", productName, " đã tồn tại");
                     return -4;
                 }
             }
         }
         try
         {
             productPrice = Convert.ToInt32(productPrice.ToString().Replace(".", ""));
             mpb.EditProduct(productId, productName, productUnit, productWeight, productDes, productNote, productPrice, dropCate, productCode, fileName, materialId, materialQuantity);
             return 2;
         }
         catch (DataException)
         {
             return -5;
         }
     }
     catch (Exception)
     {
         return -5;
     }
 }
 public ActionResult Detail(int productId)
 {
     try
     {
         if (Session["User"] == null || Session["UserRole"] == null)
         {
             return RedirectToAction("Index", "Home");
         }
         ViewBag.TreeView = "product";
         ViewBag.TreeViewMenu = "productList";
         ManageProductBusiness mpb = new ManageProductBusiness();
         var product = mpb.GetProductDetail(productId);
         var productMaterial = mpb.GetListMaterial(productId);
         ViewBag.ProductMaterial = productMaterial;
         return View(product);
     }
     catch
     {
         return RedirectToAction("ManageError", "Error");
     }
 }