// GET: MonHocs/Create public ActionResult Create() { LoaiMonHoc lmh = new LoaiMonHoc(); ViewBag.LoaiMonHoc = new SelectList(lmh.GetListLoaiMonHoc(), "LoaiMonHocID", "TenLoaiMonHoc"); return(View()); }
// GET: MonHocs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MonHoc monHoc = db.MonHocs.Find(id); if (monHoc == null) { return(HttpNotFound()); } LoaiMonHoc lmh = new LoaiMonHoc(); ViewBag.LoaiMonHoc = new SelectList(lmh.GetListLoaiMonHoc(), "LoaiMonHocID", "TenLoaiMonHoc", monHoc.LoaiMonHoc); return(View(monHoc)); }
public ActionResult Create([Bind(Include = "MonHocID,MaMonHoc,TenMonHoc,SoTinChi,LoaiMonHoc")] MonHoc monHoc) { MonHoc mh = db.MonHocs.FirstOrDefault(x => x.MaMonHoc == monHoc.MaMonHoc); LoaiMonHoc lmh = new LoaiMonHoc(); ViewBag.LoaiMonHoc = new SelectList(lmh.GetListLoaiMonHoc(), "LoaiMonHocID", "TenLoaiMonHoc"); if (mh != null) { ModelState.AddModelError("", "Mã môn học đã tồn tại trong hệ thống"); return(View(monHoc)); } if (ModelState.IsValid) { db.MonHocs.Add(monHoc); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(monHoc)); }