public ActionResult AddProduct(shopping Shopping, HttpPostedFileBase file) { string constr = ConfigurationManager.ConnectionStrings["EComm"].ConnectionString; SqlConnection con = new SqlConnection(constr); string sqlquery = "insert into [dbo].[shopping] (Product, ProductID, Cost, Category, Image, Description) VALUES (@Product, @ProductID, @Cost, @Category, @Image, @Description)"; SqlCommand com = new SqlCommand(sqlquery, con); con.Open(); com.Parameters.AddWithValue("@Product", Shopping.Product); com.Parameters.AddWithValue("@ProductID", Shopping.ProductID); com.Parameters.AddWithValue("@Cost", Shopping.Cost); com.Parameters.AddWithValue("@Category", Shopping.Category); if (file != null && file.ContentLength > 0) { string filename = Path.GetFileName(file.FileName); string imgpath = Path.Combine(Server.MapPath("~/Product-Images"), filename); file.SaveAs(imgpath); } com.Parameters.AddWithValue("@Image", "/Product-Images/" + file.FileName); com.Parameters.AddWithValue("@Description", Shopping.Description); com.ExecuteNonQuery(); con.Close(); ViewData["Message"] = "Product " + Shopping.Product + " is added successfully"; return(View()); }
public ActionResult Clothing(int?id) { ShoppingPage shoppingPage = new ShoppingPage(); if (id == null) { return(HttpNotFound()); } shopping shopping = shoppingPage.GetProductById(id); if (shopping == null) { return(HttpNotFound()); } return(View(shopping)); }
public ActionResult Add(shopping shopping) { if (Session["cart"] == null) { List <shopping> li = new List <shopping>(); li.Add(shopping); Session["cart"] = li; ViewBag.cart = li.Count(); Session["count"] = 1; } else { List <shopping> li = (List <shopping>)Session["cart"]; li.Add(shopping); Session["cart"] = li; ViewBag.cart = li.Count(); Session["count"] = Convert.ToInt32(Session["count"]) + 1; } return(RedirectToAction("Home", "Site")); }
// GET: Site/Home public ActionResult Home(shopping Shopping) { ShoppingPage shoppingPage = new ShoppingPage(); List <shopping> shoppinglist = new List <shopping>(); var GetProducts = shoppingPage.GetAllProducts(); for (int i = 0; i < GetProducts.Rows.Count; i++) { shopping shopping = new shopping(); shopping.ID = Convert.ToInt32(GetProducts.Rows[i]["ID"]); shopping.Product = Convert.ToString(GetProducts.Rows[i]["Product"]); shopping.ProductID = Convert.ToInt32(GetProducts.Rows[i]["ProductID"]); shopping.Cost = Convert.ToInt32(GetProducts.Rows[i]["Cost"]); shopping.Category = Convert.ToString(GetProducts.Rows[i]["Category"]); shopping.Image = Convert.ToString(GetProducts.Rows[i]["Image"]); shopping.Description = Convert.ToString(GetProducts.Rows[i]["Description"]); shoppinglist.Add(shopping); } return(View(shoppinglist)); }
public Item(shopping shopping, int quantity) { this.sh = shopping; this.quantity = quantity; }