public IActionResult Add(int Id, string Name) { var depart = context.Department .Where(d => d.DepartmentId == Id) .Select(d => new { DepartId = d.DepartmentId, DepartHier = d.Hierarchy, DepartParent = d.Parent }).FirstOrDefault(); var department = context.Set <Department>(); department.Add(new Department { Name = Name, Hierarchy = depart.DepartHier + 1, Parent = depart.DepartId }); context.SaveChanges(); return(RedirectToAction("Index", "Department")); }