public ActionResult SuaLNGK(int id)
        {
            LoaiNGK lngk = db.LoaiNGKs.SingleOrDefault(x => x.id_LoaiNGK == id);

            if (lngk == null)
            {
                Response.StatusCode = 404;
            }
            ViewBag.NhaCungUng = new SelectList(db.NhaCungUngs.ToList().OrderBy(n => n.TenNhaCungUng), "id_NhaCungUng", "TenNhaCungUng");
            return(View(lngk));
        }
        public ActionResult ChitietLNGK(int id)
        {
            LoaiNGK lngk = db.LoaiNGKs.SingleOrDefault(n => n.id_LoaiNGK == id);

            ViewBag.id_LoaiNGK = lngk.id_LoaiNGK;
            if (lngk == null)
            {
                Response.StatusCode = 404;
            }
            return(View(lngk));
        }
 public ActionResult SuaLNGK(LoaiNGK lngk)
 {
     ViewBag.NhaCungUng = new SelectList(db.NhaCungUngs.ToList().OrderBy(n => n.TenNhaCungUng), "id_NhaCungUng", "TenNhaCungUng");
     if (ModelState.IsValid)
     {
         LoaiNGK l = db.LoaiNGKs.Where(x => x.id_LoaiNGK == lngk.id_LoaiNGK).Single <LoaiNGK>();
         l.TenLoaiNGK = lngk.TenLoaiNGK;
         l.NhaCungUng = lngk.NhaCungUng;
         db.SaveChanges();
     }
     return(RedirectToAction("LoaiNGK"));
 }
Beispiel #4
0
        public ActionResult XacnhanxoaLNGK(int id)
        {
            LoaiNGK lngk = db.LoaiNGKs.SingleOrDefault(n => n.id_LoaiNGK == id);

            ViewBag.id_NhaCungUng = lngk.id_LoaiNGK;
            if (lngk == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.LoaiNGKs.Remove(lngk);
            db.SaveChanges();
            return(RedirectToAction("LoaiNGK"));
        }
 public ActionResult ThemmoiLNGK(LoaiNGK lngk)
 {
     ViewBag.NhaCungUng = new SelectList(db.NhaCungUngs.ToList().OrderBy(n => n.TenNhaCungUng), "id_NhaCungUng", "TenNhaCungUng");
     if (ModelState.IsValid)
     {
         var id = InsertLNGK(lngk);
         if (id > 0)
         {
             return(RedirectToAction("LoaiNGK"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm mới không thành công!");
         }
     }
     return(View(lngk));
 }
        public ActionResult XacnhanxoaLNGK(int id)
        {
            LoaiNGK lngk = db.LoaiNGKs.SingleOrDefault(n => n.id_LoaiNGK == id);

            ViewBag.id_NhaCungUng = lngk.id_LoaiNGK;
            if (lngk == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            try
            {
                db.LoaiNGKs.Remove(lngk);
                db.SaveChanges();
            }
            catch (Exception)
            {
                ModelState.AddModelError("ErrorMessage", "Dữ liệu đang được sử dụng ! Chưa thể xóa được !");
                return(View("Index"));
            }
            return(RedirectToAction("LoaiNGK"));
        }
 public int InsertLNGK(LoaiNGK model)
 {
     db.LoaiNGKs.Add(model);
     db.SaveChanges();
     return(model.id_LoaiNGK);
 }