public ActionResult Create(int id, int SanPhamID, int ThuocTinhID, string mota, string ghichu) { using (var db = new BanHangEntity()) { if (id == 0) { ThuocTinhSanPham thuocTinhSanPham = new ThuocTinhSanPham(); thuocTinhSanPham.SanPhamID = SanPhamID; thuocTinhSanPham.ThuocTinhID = ThuocTinhID; thuocTinhSanPham.NoiDungMoTa = mota; thuocTinhSanPham.GhiChu = ghichu; db.ThuocTinhSanPhams.Add(thuocTinhSanPham); } else { ThuocTinhSanPham thuocTinhSanPham = db.ThuocTinhSanPhams.Find(id); thuocTinhSanPham.ThuocTinhID = ThuocTinhID; thuocTinhSanPham.SanPhamID = SanPhamID; thuocTinhSanPham.NoiDungMoTa = mota; thuocTinhSanPham.GhiChu = ghichu; } db.SaveChanges(); return(RedirectToAction("Edit", "SanPham", new { id = SanPhamID })); } }
public ActionResult Edit(ThuocTinhSanPham sanPham) { using (var db = new BanHangEntity()) { db.Entry(sanPham).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create() { //if (Session["username"] == null) // return RedirectToAction("/Index", "Users"); //else //{ using (var db = new BanHangEntity()) { ThuocTinhSanPham sp = new ThuocTinhSanPham(); return(View(sp)); } //} }
public ActionResult Delete(int id) { using (var db = new BanHangEntity()) { ThuocTinhSanPham thuocTinhSanPham = db.ThuocTinhSanPhams.Find(id); if (thuocTinhSanPham != null) { int idSanPham = thuocTinhSanPham.SanPhamID.Value; db.ThuocTinhSanPhams.Remove(thuocTinhSanPham); db.SaveChanges(); return(RedirectToAction("Edit", "SanPham", new { id = idSanPham })); } return(RedirectToAction("Index", "SanPham")); } }
public ActionResult Delete(float id) { using (var db = new BanHangEntity()) { ThuocTinh thuocTinh = db.ThuocTinhs.Find(id); if (thuocTinh != null) { ThuocTinhSanPham thuocTinhSanPham = db.ThuocTinhSanPhams.FirstOrDefault(x => x.ThuocTinhID == thuocTinh.ThuocTinhID); if (thuocTinhSanPham != null) { db.ThuocTinhSanPhams.Remove(thuocTinhSanPham); } db.ThuocTinhs.Remove(thuocTinh); db.SaveChanges(); } } return(RedirectToAction("/Index")); }
public ActionResult Edit(int id) { //if (Session["username"] == null) // return RedirectToAction("/Index", "Users"); //else //{ using (var db = new BanHangEntity()) { try { ThuocTinhSanPham sanPham = db.ThuocTinhSanPhams.Find(id); return(View(sanPham)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(404, "Error in cloud - GetPLUInfo" + ex.Message)); } } //} }