public ActionResult DeleteConfirmed(int id, audit_trail audit) { var check = db.instructors.Where(s => s.Instructor_Type_ID == id).FirstOrDefault(); if (check == null) { instructor_type instructor_type = db.instructor_type.Find(id); var userId = System.Web.HttpContext.Current.Session["UserID"] as String; int IntID = Convert.ToInt32(userId); audit.Employee_ID = IntID; audit.Trail_DateTime = DateTime.Now.Date; audit.Deleted_Record = instructor_type.Instructor_Type_ID.ToString() + " " + instructor_type.Instructor_Type_Name + " " + instructor_type.Instrutor_Type_Description; audit.Trail_Description = "Deleted a Instructor Type"; db.audit_trail.Add(audit); db.instructor_type.Remove(instructor_type); db.SaveChanges(); return(RedirectToAction("Index")); } else { instructor_type instructor_type = db.instructor_type.Find(id); ViewBag.Error = "Can't delete a type that is in-use please add a new type instead, or delete all instructors related to this type first."; return(View(instructor_type)); } }
// GET: instructor_type/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } instructor_type instructor_type = db.instructor_type.Find(id); if (instructor_type == null) { return(HttpNotFound()); } return(View(instructor_type)); }
public ActionResult Edit([Bind(Include = "Instructor_Type_ID,Instructor_Type_Name,Instrutor_Type_Description")] instructor_type instructor_type) { bool val = db.instructor_type.Any(s => s.Instructor_Type_Name == instructor_type.Instructor_Type_Name && s.Instructor_Type_ID != instructor_type.Instructor_Type_ID); if (ModelState.IsValid && val == false) { db.Entry(instructor_type).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else if (val == true) { ViewBag.StatusMessage = "There is already an: " + instructor_type.Instructor_Type_Name + " type in the database."; return(View()); } return(View(instructor_type)); }
public ActionResult Create([Bind(Include = "Instructor_Type_ID,Instructor_Type_Name,Instrutor_Type_Description")] instructor_type instructor_type) { bool val = Validate(instructor_type.Instructor_Type_Name); if (ModelState.IsValid && val == false) { db.instructor_type.Add(instructor_type); db.SaveChanges(); return(RedirectToAction("Index")); } else if (val == true) { ViewBag.StatusMessage = "There is already an: " + instructor_type.Instructor_Type_Name + " type in the database."; return(View()); } return(View(instructor_type)); }