Esempio n. 1
0
 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 }));
     }
 }
Esempio n. 2
0
 public ActionResult Edit(ThuocTinhSanPham sanPham)
 {
     using (var db = new BanHangEntity())
     {
         db.Entry(sanPham).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 3
0
 public ActionResult Create()
 {
     //if (Session["username"] == null)
     //    return RedirectToAction("/Index", "Users");
     //else
     //{
     using (var db = new BanHangEntity())
     {
         ThuocTinhSanPham sp = new ThuocTinhSanPham();
         return(View(sp));
     }
     //}
 }
Esempio n. 4
0
 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"));
     }
 }
Esempio n. 5
0
 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"));
 }
Esempio n. 6
0
 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));
         }
     }
     //}
 }