public ActionResult Create(VMDepartmentCreate model) { User loggedUser = Session["LoggedUser"] as User; Department department = new Department { Name = model.Name, MaxEmployees = model.MaxEmployees, MinEmployees = model.MinEmployees, CreateDate = DateTime.Now, IsActive = true, RootLevel = 1, // Parent departman seçilmişse zaten if bloğunda ona göre doldurma yapılacak, default hali bu. StoreId = loggedUser.StoreId }; if (model.ParentDepartmentId != null) { department.RootLevel = Convert.ToByte(_uow.DepartmentManager.BringParentRootValue(model.ParentDepartmentId) + 1); department.ParentDepartmentId = model.ParentDepartmentId; } var result = _uow.DepartmentManager.Add(department); if (_uow.SaveChanges()) { TempData["ProcessResult"] = "Department created successfully."; TempData["AlertType"] = "success"; return(RedirectToAction("List")); } else { TempData["ProcessResult"] = "An unexpected error occurred while creating the department."; TempData["AlertType"] = "danger"; return(RedirectToAction("List")); } }