private void ValidateOneAdministratorAssignmentPerInstructor(Department department)
        {
            if (department.InstructorID != null)
            {
                Department duplicateDepartment = db.Departments
                .Include("Administrator")
                .Where(d => d.InstructorID == department.InstructorID)
                .AsNoTracking()
                .FirstOrDefault();

                if (duplicateDepartment != null && duplicateDepartment.DepartmentID != department.DepartmentID)
                {
                    string errorMessage = String.Format(
                    "Instructor {0} {1} is already administrator of the {2} department.",
                    duplicateDepartment.Administrator.FirstMidName,
                    duplicateDepartment.Administrator.LastName,
                    duplicateDepartment.Name);
                    ModelState.AddModelError(string.Empty, errorMessage);
                }
            }
        }
 public ActionResult Delete(Department department)
 {
     try
     {
         db.Entry(department).State = EntityState.Deleted;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     catch (DbUpdateConcurrencyException)
     {
         return RedirectToAction("Delete", new { concurrencyError = true });
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name after DataException and add a line here to write a log.
         ModelState.AddModelError(string.Empty, "Unable to delete. Try again, and if the problem persists contact your system administrator.");
         return View(department);
     }
 }