public ActionResult DatHangCF(FormCollection f) { if (Session["ShoppingCart"] != null) { //Lấy list sản phẩm trong giỏ hàng hiện tại List<OrderItem> lsProduct = Session["ShoppingCart"] as List<OrderItem>; var name = f["name"]; var mail = f["mail"]; var addr = f["addr"]; var phone = f["phone"]; var date = String.Format("{0:dd/MM/yyyy}", DateTime.Now); decimal total = 0; decimal.TryParse(f["total"], out total); Order p = new Order() { orderdate = date, email = mail, subtotal = total, salestax = 0, shipping = 0, name = name, addr = addr, phone = phone, trangthai="Chưa xử lý" }; using (var db = new CartEntities()) { db.Orders.Add(p); db.SaveChanges(); } foreach (OrderItem item in lsProduct) { OrderItem oi = new OrderItem(); oi.ordernum = p.ordernum; oi.productid = item.productid; oi.name = item.name; oi.price = item.price; oi.image = item.image; oi.quantity = item.quantity; db.OrderItems.Add(oi); db.SaveChanges(); } Session["ShoppingCart"] = null; return RedirectToAction("Index","Home"); } return RedirectToAction("Index", "Home"); }
public ActionResult DeleteProduct(string id) { using (var db = new CartEntities()) { var p = db.Categories.FirstOrDefault(e => e.catid.Equals(id)); if (p != null) { p.deleflag = true; db.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult SaveData(Category t) { if (t != null) { Category p = new Category() { catid = t.catid, name = t.name, desc = t.desc, }; using (var db = new CartEntities()) { db.Categories.Add(p); db.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult UpdateProduct(FormCollection f) { var id = f["editcode"]; var name = f["editname"]; var desc = f["editdesc"]; CartEntities db = new CartEntities(); var p = db.Categories.FirstOrDefault(e => e.catid.Equals(id)); p.name = name; p.desc = desc; db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult UpdateProduct(FormCollection f) { int kt = 0; var type = f["type"]; var category = f["editcategories"]; var id = f["editcode"]; var name = f["editname"]; decimal price = 0; decimal.TryParse(f["editprice"], out price); var sizes = f["editsize"]; var fileName = ""; var fl = f["editfile"]; if (type == "Create") { if (db.Products.Find(id) == null) { if (Request.Files["editfile"] != null && Request.Files["editfile"].ContentLength > 0) { fileName = Path.GetFileName(Request.Files["editfile"].FileName); // store the file inside ~/App_Data/uploads folder var path = Path.Combine(Server.MapPath("~/Resource/images/"), fileName); Request.Files["editfile"].SaveAs(path); } Product p = new Product() { catid = category, productid = id, name = name, price = price, size = sizes, thumbnail = fileName, image = fileName, shorttext = "", longtext = "", deleflag = false }; using (var db = new CartEntities()) { db.Products.Add(p); db.SaveChanges(); kt = 1; } } else ViewBag.mes = "Sản Phẩm đã tồn tại"; } else if (type == "Update") { CartEntities db = new CartEntities(); var p = db.Products.FirstOrDefault(e => e.productid.Equals(id)); p.name = name; p.catid = category; p.size = sizes; p.price = price; if (Request.Files["editfile"] != null && Request.Files["editfile"].ContentLength > 0) { fileName = Path.GetFileName(Request.Files["editfile"].FileName); // store the file inside ~/App_Data/uploads folder var path = Path.Combine(Server.MapPath("~/Resource/images/"), fileName); p.image = fileName; p.thumbnail = fileName; db.SaveChanges(); Request.Files["editfile"].SaveAs(path); } else { db.SaveChanges(); kt = 1; } } return RedirectToAction("Index"); }