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 UpdateProductMaterial(FormCollection f, int productId, string strURL) { ManageProductBusiness mpb = new ManageProductBusiness(); String[] lstQuantity = f["txtQuantity"].ToString().Split(','); mpb.UpdateProductMaterial(productId, lstQuantity); return Redirect(strURL); }
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 Index() { 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.GetProduct().OrderByDescending(n => n.IsActive).ToList(); return View(product); } catch { return RedirectToAction("ManageError", "Error"); } }
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"); } }
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 ActionResult DeleteProductMaterial(int productId, int productMaterialId, string strURL) { ManageProductBusiness mpb = new ManageProductBusiness(); mpb.DeleteProductMaterial(productId, productMaterialId); return Redirect(strURL); }
public int ChangeStatus(int productId, bool status, string strURL) { try { ManageProductBusiness mpb = new ManageProductBusiness(); Product product = db.Products.SingleOrDefault(n => n.ProductId == productId); var radioButton = Convert.ToBoolean(Request.Form["status"]); if (product.IsActive == radioButton && product.IsActive) { return -2; } if (product.IsActive == radioButton && !product.IsActive) { return -3; } mpb.ChangeStatus(productId, radioButton); return 1; } catch { return -1; } }
public int AddTempProductInfor(string productName, string productUnit, double? productWeight, string productDes, string productNote, int? productPrice, int dropCate, string fileName, int[] materialId, int[] materialQuantity) { try { Product product = new Product(); product.ProductName = productName; product.Unit = productUnit; if (productWeight == null) { product.ProductWeight = -1; } else { product.ProductWeight = productWeight.Value; } product.Descriptions = productDes; product.Note = productNote; if (productPrice == null) { product.ProductStandardPrice = -1; } else { product.ProductStandardPrice = productPrice.Value; } product.CategoryId = dropCate; product.ProductImage = fileName; Session["ProductInfor"] = product; ManageProductBusiness mpb = new ManageProductBusiness(); List<AllProductInfoViewModel> apivList = new List<AllProductInfoViewModel>(); if (materialId != null && materialQuantity != null && materialQuantity.Length > 0 && materialId.Length > 0) { for (int i = 0; i < materialId.Length; i++) { var pm = mpb.GetMaterialById(materialId[i]); AllProductInfoViewModel apiv = new AllProductInfoViewModel { MaterialId = pm.ProductMaterialId, MaterialName = pm.ProductMaterialName, MaterialUnit = pm.ProductMaterialUnit, MaterialQuantity = materialQuantity[i] }; apivList.Add(apiv); } } if (apivList.Count > 0) { Session["Material"] = apivList; } return 1; } catch { return -1; } }
public ActionResult AddProductMaterial(FormCollection form) { ManageProductBusiness mpb = new ManageProductBusiness(); int productId = int.Parse(form["productId"]); int materialId = int.Parse(form["productMaterialId"]); string strURL = String.Format("{0}{1}", "/ManageProduct/ProductMaterial?ProductId=", productId); mpb.AddProductMaterial(productId, materialId); return Redirect(strURL); }
public int AddProduct(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(); //Check that product name had existed var productList = mpb.GetActiveProduct(); string productCode = CreateProductCode(productName); for (int i = 0; i < productList.Count; i++) { if (StringComparer.CurrentCultureIgnoreCase.Equals(productName, productList[i].ProductName)) { //string strURL = Request.UrlReferrer.AbsolutePath; //TempData["Error"] = String.Format("{0}{1}", productName, " đã tồn tại"); return -4; } } productPrice = Convert.ToInt32(productPrice.ToString().Replace(".", "")); mpb.AddProduct(productName, productUnit, productWeight, productDes, productNote, productPrice, dropCate, productCode, fileName, materialId, materialQuantity); Session["ProductInfor"] = null; Session["Material"] = null; return 2; } catch (Exception) { return -5; } }