public IActionResult DeleteGroup(int departmentGroupId) { DeleteGroupView model = new DeleteGroupView(); model.Group = _departmentGroupsService.GetGroupById(departmentGroupId); if (model.Group == null || model.Group.DepartmentId != DepartmentId || !_authorizationService.CanUserEditDepartmentGroup(UserId, departmentGroupId)) { Unauthorized(); } var users = _departmentGroupsService.GetAllUsersForGroup(departmentGroupId); var childGroups = _departmentGroupsService.GetAllChildDepartmentGroups(departmentGroupId); var units = _unitsService.GetAllUnitsForGroup(departmentGroupId); var shifts = _shiftsService.GetShiftGroupsByGroupId(departmentGroupId); if (users != null) { model.UserCount = users.Count; } else { model.UserCount = 0; } if (childGroups != null) { model.ChildGroupCount = childGroups.Count; } else { model.ChildGroupCount = 0; } if (units != null) { model.UnitsCount = units.Count; } else { model.UnitsCount = 0; } if (shifts != null) { model.ShiftsCount = shifts.Count; } else { model.ShiftsCount = 0; } return(View(model)); }