public ActionResult Create(SanPham sanPham) { if (ModelState.IsValid) { //db.SanPhams.Add(sanPham); //db.SaveChanges(); //return RedirectToAction("Index"); foreach (var item in sanPham.PictureUpload) { string path = Path.Combine(Server.MapPath("~/Content/Images/"), Path.GetFileName(item.FileName)); item.SaveAs(path); string pathInDb = "/Content/Images/" + Path.GetFileName(item.FileName); HinhAnhSP img = new HinhAnhSP(); img.SanPhamID = sanPham.ID; img.SanPhamObj = sanPham; img.PicturePath = pathInDb; db.HinhAnhSPs.Add(img); } db.SanPhams.Add(sanPham); db.SaveChanges(); return(RedirectToAction("IndexPage")); } ViewBag.DanhMucID = new SelectList(db.DanhMucs, "ID", "Name", sanPham.DanhMucID); ViewBag.MaKhuyenMai = new SelectList(db.KmS, "MaKhuyenMai", "MaKhuyenMai", sanPham.MaKhuyenMai); return(View(sanPham)); }
public ActionResult Create([Bind(Include = "MaHASP,SerialNumber,LinkHASP")] HinhAnhSP hinhAnhSP) { var Image = Request.Files["Image"]; var path = Server.MapPath("~/Images/" + Image.FileName); Image.SaveAs(path); var sl = from p in db.HinhAnhSP select p; int a = sl.Count() + 1; if (ModelState.IsValid) { if (Common.MaNV != "") { } else { Common.Alert = "Đăng nhập trước khi chỉnh sữa !"; return(RedirectToAction("Index", "Logins")); } hinhAnhSP.MaHASP = a.ToString(); hinhAnhSP.LinkHASP = "/Images/" + Image.FileName; db.HinhAnhSP.Add(hinhAnhSP); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SerialNumber = new SelectList(db.SanPham, "SerialNumber", "SerialNumber", hinhAnhSP.SerialNumber); return(View(hinhAnhSP)); }
public ActionResult DeleteConfirmed(string id) { HinhAnhSP hinhAnhSP = db.HinhAnhSP.Find(id); db.HinhAnhSP.Remove(hinhAnhSP); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: HinhAnhSPs/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HinhAnhSP hinhAnhSP = db.HinhAnhSP.Find(id); if (hinhAnhSP == null) { return(HttpNotFound()); } return(View(hinhAnhSP)); }
// GET: HinhAnhSPs/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HinhAnhSP hinhAnhSP = db.HinhAnhSP.Find(id); if (hinhAnhSP == null) { return(HttpNotFound()); } ViewBag.SerialNumber = new SelectList(db.SanPham, "SerialNumber", "SerialNumber", hinhAnhSP.SerialNumber); return(View(hinhAnhSP)); }
public ActionResult Edit([Bind(Include = "MaHASP,SerialNumber,LinkHASP")] HinhAnhSP hinhAnhSP) { var Image = Request.Files["Image"]; var path = Server.MapPath("~/Images/" + Image.FileName); Image.SaveAs(path); if (ModelState.IsValid) { if (Common.MaNV != "") { } else { Common.Alert = "Đăng nhập trước khi chỉnh sữa !"; return(RedirectToAction("Index", "Logins")); } hinhAnhSP.LinkHASP = "/Images/" + Image.FileName; db.Entry(hinhAnhSP).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SerialNumber = new SelectList(db.SanPham, "SerialNumber", "SerialNumber", hinhAnhSP.SerialNumber); return(View(hinhAnhSP)); }