예제 #1
0
        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");
        }
예제 #2
0
        public ActionResult DeleteProduct(string id)
        {
            ProductModel model = new ProductModel();
            model.DeleteProductByName(id);

            TempData["notify"] = "Product '" + id + "' has been delete!";

            return RedirectToAction("Panel");
        }
예제 #3
0
        public ActionResult DeleteImage(string id)
        {
            ProductModel model = new ProductModel();
            model.DeleteImage(id);

            List<string> t = new List<string>();

            return RedirectToAction("Panel");
        }
예제 #4
0
        public ActionResult Edit(string id)
        {
            if(!Request.IsAuthenticated)
            {
                return RedirectToAction("Index");
            }

            ProductModel product = new ProductModel();
            ViewBag.Product = product.GetProductByName(id);

            return View();
        }
예제 #5
0
        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");
        }
예제 #6
0
        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");
        }
예제 #7
0
        public ActionResult Product(string id)
        {
            ProductModel model = new ProductModel();
            ViewBag.Product = model.GetProductByName(id);
            if (ViewBag.Product == null)
            {
                return RedirectToAction("Index", "Home");
            }

            return View();
        }
예제 #8
0
        public ActionResult Panel()
        {
            if (!Request.IsAuthenticated)
            {
                return RedirectToAction("Index");
            }

            ProductModel model = new ProductModel();
            ViewBag.Products = model.GetAllProducts();

            return View();
        }
예제 #9
0
        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;
        }
예제 #10
0
        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;
                }

            }
        }