public ActionResult Xacnhanxoa(int id) { RUOU ruou = data.RUOUs.SingleOrDefault(n => n.MaRuou == id); ViewBag.MaRuou = ruou.MaRuou; if (ruou == null) { Response.StatusCode = 404; return(null); } var filePath = Path.Combine(Server.MapPath("~/Images/"), ruou.AnhRuou); try { data.RUOUs.DeleteOnSubmit(ruou); data.SubmitChanges(); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } catch (Exception) { ViewBag.ErRemove = "Bạn phải xóa các màu của sản phẩm"; } return(RedirectToAction("Ruou")); }
public ActionResult ThemRuoumoi(RUOU ruou, HttpPostedFileBase fileUpload) { ViewBag.MaLoaiRuou = new SelectList(data.LOAIRUOUs.ToList().OrderBy(n => n.TenLoaiRuou), "MaLoaiRuou", "TenLoaiRuou"); ViewBag.MaNSX = new SelectList(data.NHASANXUATs.ToList().OrderBy(n => n.TenNSX), "MaNSX", "TenNSX"); ViewBag.MaNNK = new SelectList(data.NUOCNHAPKHAUs.ToList().OrderBy(n => n.TenNNK), "MaNNK", "TenNNK"); // ViewBag.Vip = new SelectList("0", "1","2"); if (fileUpload == null) { ViewBag.Thongbao = "Vui lòng chọn hình ảnh rượu"; return(View()); } else { if (ModelState.IsValid) { var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/images/"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } ruou.AnhRuou = fileName; data.RUOUs.InsertOnSubmit(ruou); data.SubmitChanges(); } return(RedirectToAction("Ruou")); } }
public Giohang(int Maruou) { iMaruou = Maruou; RUOU ruou = data.RUOUs.Single(t => t.MaRuou == iMaruou); sTenruou = ruou.TenRuou; sAnhruou = ruou.AnhRuou; dDongia = double.Parse(ruou.Giaban.ToString()); iSoluong = 1; }
public ActionResult Xoaruou(int id) { RUOU ruou = data.RUOUs.SingleOrDefault(n => n.MaRuou == id); ViewBag.Maruou = ruou.MaRuou; if (ruou == null) { Response.StatusCode = 404; return(null); } return(View(ruou)); }
public ActionResult Suaruou(RUOU ruou, HttpPostedFileBase NewImageP, FormCollection col) { ViewBag.MaLoairuou = new SelectList(data.PHANLOAIs.ToList().OrderBy(t => t.Loairuou), "MaLoaiRuou", "Loairuou"); ViewBag.MaXXu = new SelectList(data.XUATXUs.ToList().OrderBy(t => t.TenXXu), "MaXXu", "TenXXu"); ViewBag.MaNCC = new SelectList(data.NHACUNGCAPs.ToList().OrderBy(t => t.TenNCC), "MaNCC", "TenNCC"); var image = col["ImageP"]; RUOU r = data.RUOUs.First(n => n.MaRuou == ruou.MaRuou); if (ModelState.IsValid) { if (NewImageP != null) { if (Path.GetExtension(NewImageP.FileName).ToLower() == ".jpg" || Path.GetExtension(NewImageP.FileName).ToLower() == ".png" || Path.GetExtension(NewImageP.FileName).ToLower() == ".gif" || Path.GetExtension(NewImageP.FileName).ToLower() == ".jpeg" ) { var filename = Path.GetFileName(NewImageP.FileName); var path = Path.Combine(Server.MapPath("~/Images/"), filename); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Tên ảnh đã tồn tại"; } else { var newImageP = NewImageP.FileName; NewImageP.SaveAs(path); r.AnhRuou = newImageP; r.NgayCapNhat = DateTime.Now; UpdateModel(r); data.SubmitChanges(); return(RedirectToAction("Ruou")); } } else { ViewBag.Thongbao = "Hãy chọn một ảnh"; } } else { r.AnhRuou = image; r.NgayCapNhat = DateTime.Now; UpdateModel(r); data.SubmitChanges(); return(RedirectToAction("Ruou")); } } return(this.Suaruou(r.MaRuou)); }
public ActionResult Xacnhanxoa(int id) { RUOU ruou = data.RUOUs.SingleOrDefault(n => n.MaRuou == id); ViewBag.Maruou = ruou.MaRuou; if (ruou == null) { Response.StatusCode = 404; return(null); } data.RUOUs.DeleteOnSubmit(ruou); data.SubmitChanges(); return(RedirectToAction("Ruou")); }
public ActionResult Suaruou(int id) { RUOU ruou = data.RUOUs.SingleOrDefault(n => n.MaRuou == id); if (ruou == null) { Response.StatusCode = 404; return(null); } ViewBag.MaLoaiRuou = new SelectList(data.LOAIRUOUs.ToList().OrderBy(n => n.TenLoaiRuou), "MaLoaiRuou", "TenLoaiRuou", ruou.MaLoaiRuou); ViewBag.MaNSX = new SelectList(data.NHASANXUATs.ToList().OrderBy(n => n.TenNSX), "MaNSX", "TenNSX", ruou.MaNSX); ViewBag.MaNNK = new SelectList(data.NUOCNHAPKHAUs.ToList().OrderBy(n => n.TenNNK), "MaNNK", "TenNNK", ruou.MaNNK); return(View(ruou)); }
public ActionResult xoaruou(int id) { if (Session["Taikhoanadmin"] == null || Session["Taikhoanadmin"].ToString() == "") { return(RedirectToAction("Login")); } RUOU ruou = data.RUOUs.SingleOrDefault(n => n.MaRuou == id); ViewBag.MaRuou = ruou.MaRuou; if (ruou == null) { Response.StatusCode = 404; return(null); } return(View(ruou)); }
public ActionResult Suaruou(int id) { if (Session["Taikhoanadmin"] == null || Session["Taikhoanadmin"].ToString() == "") { return(RedirectToAction("Login")); } RUOU ruou = data.RUOUs.SingleOrDefault(n => n.MaRuou == id); ViewBag.MaRuou = ruou.MaRuou; ViewData["Image"] = ruou.AnhRuou; if (ruou == null) { Response.StatusCode = 404; return(null); } ViewBag.MaLoairuou = new SelectList(data.PHANLOAIs.ToList().OrderBy(t => t.Loairuou), "MaLoaiRuou", "Loairuou"); ViewBag.MaXXu = new SelectList(data.XUATXUs.ToList().OrderBy(t => t.TenXXu), "MaXXu", "TenXXu"); ViewBag.MaNCC = new SelectList(data.NHACUNGCAPs.ToList().OrderBy(t => t.TenNCC), "MaNCC", "TenNCC"); return(View(ruou)); }
public ActionResult themmoiruou(RUOU ruou, HttpPostedFileBase fileUpload, FormCollection collection) { var filename = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/Images"), filename); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } var tenruou = collection["TenRuou"]; var giaban = collection["Giaban"]; var mota = collection["Mota"]; var ngaycapnhat = collection["sel_date"]; var slton = collection["SoLuongTon"]; var malr = collection["MaLoaiRuou"]; var maxx = collection["MaXXu"]; var mancc = collection["MaNCC"]; ruou.TenRuou = tenruou; ruou.AnhRuou = filename; ruou.Giaban = Decimal.Parse(giaban); ruou.Mota = Regex.Replace(mota, "<.*?>", String.Empty); ruou.NgayCapNhat = Convert.ToDateTime(ngaycapnhat); ruou.SoLuongTon = Int32.Parse(slton); ruou.MaLoaiRuou = Int32.Parse(malr); ruou.MaNCC = Int32.Parse(mancc); ruou.MaXXu = Int32.Parse(maxx); data.RUOUs.InsertOnSubmit(ruou); data.SubmitChanges(); ViewBag.MaLoairuou = new SelectList(data.PHANLOAIs.ToList().OrderBy(t => t.Loairuou), "MaLoairuou", "Loairuou"); ViewBag.MaXXu = new SelectList(data.XUATXUs.ToList().OrderBy(t => t.TenXXu), "MaXXu", "TenXXu"); ViewBag.MaNCC = new SelectList(data.NHACUNGCAPs.ToList().OrderBy(t => t.TenNCC), "MaNCC", "TenNCC"); return(RedirectToAction("Ruou")); }
public ActionResult ChiTietSP(int id) { RUOU ct = data.RUOUs.SingleOrDefault(t => t.MaRuou == id); return(View(ct)); }