public ActionResult Edit([Bind(Include = "Course_Id,Department_Id,Course_Type_Id,Course_Code,Course_Name,Course_Name_Eng,Created_By,Created_Date,Modified_By,Modified_Date,Order_Id")] Acd_Course acd_Course) { if (ModelState.IsValid) { db.Entry(acd_Course).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateException) { Acd_Course course = db.Acd_Course.Find(acd_Course.Course_Id); if (course == null) { return(HttpNotFound()); } TempData["shortMessage"] = "Data ganda, data matakuliah yang akan di tambahkan telah ada."; return(RedirectToAction("Edit", acd_Course)); throw; } ViewBag.Department_Id = new SelectList(db.Mstr_Department.OrderBy(d => d.Department_Code), "Department_Id", "Department_Name", acd_Course.Department_Id); return(RedirectToAction("Index", new { Department_Id = acd_Course.Department_Id })); } ViewBag.Course_Type_Id = new SelectList(db.Acd_Course_Type, "Course_Type_Id", "Course_Type_Name", acd_Course.Course_Type_Id); ViewBag.Department = db.Mstr_Department.Where(d => d.Department_Id == acd_Course.Department_Id).FirstOrDefault(); return(View(acd_Course)); }
// GET: Course_LecturerDM/Create //public ActionResult Create() //{ // //ViewBag.Course_Id = new SelectList(db.Acd_Course, "Course_Id", "Course_Name"); -> Generated ByJson // ViewBag.Department_Id = new SelectList(db.Mstr_Department, "Department_Id", "Department_Name"); // ViewBag.Employee_Id = new SelectList(db.Emp_Employee.Where(e => e.Emp_Employee_Status.Description.Contains("Dosen")).Select(e => new { e.Employee_Id, employeetext = e.Full_Name + " [" + e.Nik + "]" }).ToList().OrderBy(e => e.employeetext), "Employee_Id", "employeetext"); // return View(); //} // GET: Course_LecturerDM/Create public ActionResult Create(short?Department_Id, int?Course_Id) { ViewBag.Department_Id = new SelectList(db.Mstr_Department, "Department_Id", "Department_Name"); ViewBag.Employee_Id = new SelectList(db.Emp_Employee.Where(e => e.Emp_Employee_Status.Description.Contains("Dosen")) .Select(e => new { e.Employee_Id, employeetext = e.Full_Name + " [" + e.Nik + "]" }) .ToList() .OrderBy(e => e.employeetext), "Employee_Id", "employeetext"); /*Course_Id Selected*/ if (Course_Id != null) { Acd_Course acd_course = db.Acd_Course.Find(Course_Id); ViewBag.Course_Id = new SelectList(db.Acd_Course.Where(c => c.Department_Id == Department_Id) .Select(c => new { c.Course_Id, coursetext = c.Course_Name + " [" + c.Course_Code + "] " }) .ToList() .OrderBy(c => c.coursetext), "Course_Id", "coursetext", acd_course.Course_Id); } else { ViewBag.Course_Id = new SelectList(db.Acd_Course.Where(c => c.Department_Id == Department_Id) .Select(c => new { c.Course_Id, coursetext = c.Course_Name + " [" + c.Course_Code + "] " }) .ToList() .OrderBy(c => c.coursetext), "Course_Id", "coursetext"); } return(View()); }
// GET: Course/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Acd_Course acd_Course = db.Acd_Course.Find(id); if (acd_Course == null) { return(HttpNotFound()); } return(View(acd_Course)); }
public ActionResult DeleteConfirmed(int id) { Acd_Course acd_Course = db.Acd_Course.Find(id); try { db.Acd_Course.Where(c => c.Course_Id.Equals(id)).Delete(); } catch (Exception) { TempData["gagalHapus"] = "Gagal Hapus, Data sudah digunakan"; return(RedirectToAction("Index", new { Department_Id = acd_Course.Department_Id })); } //ViewBag.Department_Id = new SelectList(db.Mstr_Department.OrderBy(d => d.Department_Code), "Department_Id", "Department_Name", acd_Course.Department_Id); TempData["berhasilHapus"] = "Berhasil Hapus Data."; return(RedirectToAction("Index", new { Department_Id = acd_Course.Department_Id })); }
public ActionResult Create([Bind(Include = "Course_Id,Department_Id,Course_Type_Id,Course_Code,Course_Name,Course_Name_Eng,Created_By,Created_Date,Modified_By,Modified_Date,Order_Id")] Acd_Course acd_Course) { if (ModelState.IsValid) { db.Acd_Course.Add(acd_Course); db.SaveChanges(); ViewBag.Department_Id = new SelectList(db.Mstr_Department.OrderBy(d => d.Department_Code), "Department_Id", "Department_Name", acd_Course.Department_Id); return(RedirectToAction("Index", new { Department_Id = acd_Course.Department_Id })); } ViewBag.Course_Type_Id = new SelectList(db.Acd_Course_Type, "Course_Type_Id", "Course_Type_Name", acd_Course.Course_Type_Id); ViewBag.Department = db.Mstr_Department.Where(d => d.Department_Id == acd_Course.Department_Id).FirstOrDefault(); //ViewBag.Department_Id = new SelectList(db.Mstr_Department, "Department_Id", "Department_Code", acd_Course.Department_Id); return(View(acd_Course)); }
// GET: Course/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (TempData["shortMessage"] != null) { ViewBag.message = TempData["shortMessage"].ToString(); } Acd_Course acd_Course = db.Acd_Course.Find(id); if (acd_Course == null) { return(HttpNotFound()); } ViewBag.Course_Type_Id = new SelectList(db.Acd_Course_Type, "Course_Type_Id", "Course_Type_Name", acd_Course.Course_Type_Id); ViewBag.Department = db.Mstr_Department.Where(d => d.Department_Id == acd_Course.Department_Id).FirstOrDefault(); return(View(acd_Course)); }