예제 #1
0
        public async Task <IActionResult> DeleteGroup(int departmentGroupId)
        {
            DeleteGroupView model = new DeleteGroupView();

            model.Group = await _departmentGroupsService.GetGroupByIdAsync(departmentGroupId);

            if (model.Group == null || model.Group.DepartmentId != DepartmentId || !await _authorizationService.CanUserEditDepartmentGroupAsync(UserId, departmentGroupId))
            {
                Unauthorized();
            }

            var users       = _departmentGroupsService.GetAllUsersForGroup(departmentGroupId);
            var childGroups = await _departmentGroupsService.GetAllChildDepartmentGroupsAsync(departmentGroupId);

            var units = await _unitsService.GetAllUnitsForGroupAsync(departmentGroupId);

            var shifts = await _shiftsService.GetShiftGroupsByGroupIdAsync(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));
        }