예제 #1
0
 // GET: SinhVienThuocKhoa/Delete/5
 public ActionResult Delete(decimal?KId, string SVId)
 {
     if (!UserManager.Authenticated)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         if (KId == 0 || SVId == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         SinhVienThuocKhoa sinhVienThuocKhoa = db.SinhVienThuocKhoas.Find(KId, SVId);
         if (sinhVienThuocKhoa == null)
         {
             return(HttpNotFound());
         }
         var kh = db.Khoas.Where(n => n.KhoaId == KId).SingleOrDefault();
         if (kh != null)
         {
             ViewBag.IdKhoa  = kh.KhoaId;
             ViewBag.TenKhoa = kh.TenKhoa;
         }
         return(View(sinhVienThuocKhoa));
     }
 }
예제 #2
0
 // GET: SinhVienThuocKhoa/Edit/5
 public ActionResult Edit(decimal KId = 0, string SVId = null)
 {
     if (!UserManager.Authenticated)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         if (KId == 0 || SVId == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         SinhVienThuocKhoa sinhVienThuocKhoa = db.SinhVienThuocKhoas.Find(KId, SVId);
         if (sinhVienThuocKhoa == null)
         {
             return(HttpNotFound());
         }
         var kh = db.Khoas.Where(n => n.KhoaId == KId).SingleOrDefault();
         if (kh != null)
         {
             ViewBag.TenKhoa = kh.TenKhoa;
             ViewBag.IdKhoa  = kh.KhoaId;
             ViewBag.KhoaID  = new SelectList(db.Khoas, "KhoaId", "TenKhoa", kh.KhoaId);
         }
         else
         {
             ViewBag.KhoaID = new SelectList(db.Khoas, "KhoaId", "TenKhoa");
         }
         ViewBag.KhoaID     = new SelectList(db.Khoas, "KhoaId", "TenKhoa", sinhVienThuocKhoa.KhoaId);
         ViewBag.SinhVienId = new SelectList(db.SinhViens, "SinhVienId", "HoTen", sinhVienThuocKhoa.SinhVienId);
         return(View(sinhVienThuocKhoa));
     }
 }
예제 #3
0
        public ActionResult Create([Bind(Include = "KhoaId,SinhVienId,TuNgay,DenNgay")] SinhVienThuocKhoa sinhVienThuocKhoa)
        {
            if (ModelState.IsValid)
            {
                //if (db.SinhVienThuocKhoas.Any(p => p.SinhVienId == sinhVienThuocKhoa.SinhVienId))
                //{
                //    ModelState.AddModelError("TenSinhVien", "Sinh Vien Da Ton Tai.");
                //}

                var svKh = db.SinhVienThuocKhoas.Where(n => n.KhoaId == sinhVienThuocKhoa.KhoaId).ToList();
                if (svKh == null)
                {
                    return(HttpNotFound());
                }
                var kh = db.Khoas.Where(n => n.KhoaId == sinhVienThuocKhoa.KhoaId).SingleOrDefault();
                if (kh != null)
                {
                    ViewBag.IdKhoaHoc  = kh.KhoaId;
                    ViewBag.TenKhoaHoc = kh.TenKhoa;
                }

                db.SinhVienThuocKhoas.Add(sinhVienThuocKhoa);
                db.SaveChanges();
                return(RedirectToAction("DSSV", new { KId = sinhVienThuocKhoa.KhoaId }));
            }
            return(View(sinhVienThuocKhoa));
        }
예제 #4
0
        public ActionResult DeleteConfirmed(decimal?KId, string SVId)
        {
            SinhVienThuocKhoa sinhVienThuocKhoa = db.SinhVienThuocKhoas.Find(KId, SVId);

            db.SinhVienThuocKhoas.Remove(sinhVienThuocKhoa);
            db.SaveChanges();
            return(RedirectToAction("DSSV", new { KId = sinhVienThuocKhoa.KhoaId }));
        }
예제 #5
0
 public ActionResult Edit([Bind(Include = "KhoaId,SinhVienId,TuNgay,DenNgay")] SinhVienThuocKhoa sinhVienThuocKhoa)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sinhVienThuocKhoa).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("DSSV", new { KId = sinhVienThuocKhoa.KhoaId }));
     }
     ViewBag.KhoaId     = new SelectList(db.Khoas, "KhoaId", "TenKhoa", sinhVienThuocKhoa.KhoaId);
     ViewBag.SinhVienId = new SelectList(db.SinhViens, "SinhVienId", "HoTen", sinhVienThuocKhoa.SinhVienId);
     return(View(sinhVienThuocKhoa));
 }
예제 #6
0
 // GET: SinhVienThuocKhoa/Details/5
 public ActionResult Details(decimal id)
 {
     if (!UserManager.Authenticated)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         SinhVienThuocKhoa sinhVienThuocKhoa = db.SinhVienThuocKhoas.Find(id);
         if (sinhVienThuocKhoa == null)
         {
             return(HttpNotFound());
         }
         return(View(sinhVienThuocKhoa));
     }
 }