public ActionResult Create(CreateForm form) { if (ModelState.IsValid) { C.Department Department = new C.Department(form.Title, DateTime.Now, form.Description, SessionUser.GetUser().Id, true); int?DepId = DepartmentService.Create(Department, SessionUser.GetUser().Id); if (DepId != null) { if (DepartmentService.ChangeHeadOfDepartment((int)DepId, form.SelectedHeadOfDepartmentId, SessionUser.GetUser().Id)) { return(RedirectToAction("Index")); } } IEnumerable <C.Employee> Employees = EmployeeService.GetAllActive(); List <SelectListItem> HeadOfDepartmentCandidates = new List <SelectListItem>(); foreach (C.Employee emp in Employees) { HeadOfDepartmentCandidates.Add(new SelectListItem() { Text = emp.FirstName + " " + emp.LastName + " (" + emp.Email + ")", Value = emp.Employee_Id.ToString() }); } form.HeadOfDepartmentCandidateList = HeadOfDepartmentCandidates; } return(View(form)); }
public ActionResult Edit(int id, EditForm form) { if (ModelState.IsValid) { C.Department Department = new C.Department(form.Id, form.Title, DateTime.Now, form.Description, SessionUser.GetUser().Id, form.Active); try { if (DepartmentService.Edit(SessionUser.GetUser().Id, Department)) { DepartmentService.ChangeHeadOfDepartment(id, form.SelectedHeadOfDepartmentId, SessionUser.GetUser().Id); return(RedirectToAction("Index")); } } catch { return(View()); } return(RedirectToAction("Edit")); } return(View()); }