Example #1
0
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PersonID = new SelectList(db.Instructors, "PersonID", "FullName");
            return View(department);
        }
Example #2
0
 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);
     }
 }