public ActionResult List() { var model = new DepartmentsViewModel { Departments = Context.Departments.OrderBy(x => x.Name).ToList() }; return View(model); }
public ActionResult Create(DepartmentsViewModel model) { if (!ModelState.IsValid) { model.Departments = Context.Departments.OrderBy(x => x.Name).ToList(); return View("List", model); } var departmentService = new DepartmentService(Context); departmentService.Create(model.NewDepartmentName); return RedirectToAction("List"); }