Example #1
0
        public ActionResult Edit(VMDepartmentEdit model)
        {
            int selectedDepartmentId = Convert.ToInt32(Session["SelectedDepartmentId"]);

            Department department = _uow.DepartmentManager.Get(x => x.DepartmentId == selectedDepartmentId);

            department.Name         = model.Name;
            department.MaxEmployees = model.MaxEmployees;
            department.MinEmployees = model.MinEmployees;

            if (department.ParentDepartmentId != model.ParentDepartmentId)
            {
                department.RootLevel          = Convert.ToByte(_uow.DepartmentManager.BringParentRootValue(model.ParentDepartmentId) + 1);
                department.ParentDepartmentId = model.ParentDepartmentId;
            }

            var result = _uow.DepartmentManager.Update(department);

            Session.Remove("SelectedDepartmentId");
            if (_uow.SaveChanges())
            {
                TempData["ProcessResult"] = "Department updated successfully.";
                TempData["AlertType"]     = "success";
                return(RedirectToAction("List"));
            }
            else
            {
                TempData["ProcessResult"] = "An enexpected error occurred while updating the department.";
                TempData["AlertType"]     = "danger";
                return(RedirectToAction("List"));
            }
        }
Example #2
0
        public ActionResult Edit(int id)
        {
            User loggedUser = Session["LoggedUser"] as User;

            Session["SelectedDepartmentId"] = id; // Created to capture in post method when data is sent.

            Department department = _uow.DepartmentManager.Get(x => x.DepartmentId == id);

            if (department == null)
            {
                TempData["ProcessResult"] = "There was an error while viewing the department.";
                TempData["AlertType"]     = "danger";
                return(RedirectToAction("List"));
            }

            List <Department> allDepartments = _uow.DepartmentManager.ListAll(x => x.IsActive && x.StoreId == loggedUser.StoreId);

            VMDepartmentEdit vmDepartmentEdit = VMDepartmentEdit.Parse(department, allDepartments);

            return(View(vmDepartmentEdit));
        }