public ActionResult AddProduct() { string productName = Request["txtPrdName"]; string productDesc = Request["txtPrdDesc"]; string ProductImage = Request["txtPrdImage"]; if(productDesc.Length < 0 || productName.Length < 0 || ProductImage.Length < 0) { TempData["Error"] = "Please check all fields."; return View("Panel"); } ProductModel model = new ProductModel(); if(model.CheckIfProductNameExists(productName)) { TempData["Error"] = "Name is already taken!"; return View("Panel"); } if(!model.AddNewProduct(productName, productDesc, ProductImage)) { TempData["Error"] = "Something is wrong please try later."; return View("Panel"); } TempData["Error"] = "Product has been added!"; return RedirectToAction("Panel"); }
public ActionResult DeleteProduct(string id) { ProductModel model = new ProductModel(); model.DeleteProductByName(id); TempData["notify"] = "Product '" + id + "' has been delete!"; return RedirectToAction("Panel"); }
public ActionResult DeleteImage(string id) { ProductModel model = new ProductModel(); model.DeleteImage(id); List<string> t = new List<string>(); return RedirectToAction("Panel"); }
public ActionResult Edit(string id) { if(!Request.IsAuthenticated) { return RedirectToAction("Index"); } ProductModel product = new ProductModel(); ViewBag.Product = product.GetProductByName(id); return View(); }
public ActionResult Search(string p) { if(p.Length < 2 || p == string.Empty) { TempData["Error"] = "Please try again"; return View("Index"); } ProductModel model = new ProductModel(); List<ProductModel> products = model.GetProductsByName(p); if(products.Count < 1) { TempData["Error"] = "Could not find " + p + "."; return View("Index"); } ViewBag.Products = products; return View("Index"); }
public ActionResult SaveProduct() { string name = Request["txtName"]; string desc = Request["txtDesc"]; string image = Request["txtImage"]; string originalName = Request["hiddenName"]; ProductModel model = new ProductModel(); model.UpdateProduct(originalName, name, desc, image); TempData["notify"] = "Product has beed saved!"; return RedirectToAction("Panel"); }
public ActionResult Product(string id) { ProductModel model = new ProductModel(); ViewBag.Product = model.GetProductByName(id); if (ViewBag.Product == null) { return RedirectToAction("Index", "Home"); } return View(); }
public ActionResult Panel() { if (!Request.IsAuthenticated) { return RedirectToAction("Index"); } ProductModel model = new ProductModel(); ViewBag.Products = model.GetAllProducts(); return View(); }
public List<ProductModel> GetProductsByName(string prdName) { List<ProductModel> Products = new List<ProductModel>(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); string sSQL = "Select * from Products WHERE Name LIKE '%" + prdName + "%'"; SqlCommand cmd = new SqlCommand(sSQL, conn); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (reader.HasRows) { ProductModel Product = new ProductModel(); Product.ProductName = reader["Name"].ToString(); Products.Add(Product); } else { return null; } } } } return Products; }
public ProductModel GetProductByName(string prdName) { ProductModel Product = new ProductModel(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); string sSQL = "Select * from Products WHERE Name='" + prdName + "'"; SqlCommand cmd = new SqlCommand(sSQL, conn); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (reader.HasRows) { Product.ProductName = reader["Name"].ToString(); Product.ProductDesc = reader["Description"].ToString(); } else { return null; } } } Product.ProductImages = new List<string>(); sSQL = "Select * from ProductImages2 WHERE productName='" + Product.ProductName + "'"; cmd = new SqlCommand(sSQL, conn); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (reader.HasRows) { Product.ProductImages.Add(reader["imgUrl"].ToString()); } } return Product; } } }