public async Task <ActionResult> IndexJson(int projectId, int characterGroupId)
        {
            var field = await ProjectRepository.LoadGroupWithTreeAsync(projectId, characterGroupId);

            if (field == null)
            {
                return(HttpNotFound());
            }

            var hasMasterAccess = field.HasMasterAccess(CurrentUserIdOrDefault);

            return(ReturnJson(new
            {
                field.Project.ProjectId,
                field.Project.ProjectName,
                ShowEditControls = hasMasterAccess,
                Groups = CharacterGroupListViewModel.GetGroups(field, CurrentUserIdOrDefault).Select(
                    g =>
                    new
                {
                    g.CharacterGroupId,
                    g.Name,
                    g.DeepLevel,
                    g.FirstCopy,
                    Description = g.Description?.ToHtmlString(),
                    Path = g.Path.Select(gr => gr.Name),
                    PathIds = g.Path.Select(gr => gr.CharacterGroupId),
                    Characters = g.PublicCharacters.Select(ConvertCharacterToJson),
                    CanAddDirectClaim = g.IsAcceptingClaims,
                    DirectClaimsCount = g.AvaiableDirectSlots,
                    DirectClaimLink = g.IsAcceptingClaims ? GetFullyQualifiedUri("AddForGroup", "Claim", new { field.ProjectId, g.CharacterGroupId }) : null,
                }),
            }));
        }
        // GET: GameGroups
        public async Task <ActionResult> Index(int projectId, int?characterGroupId)
        {
            if (characterGroupId == null)
            {
                return(await RedirectToProject(projectId));
            }

            var field = await ProjectRepository.LoadGroupWithTreeAsync(projectId, (int)characterGroupId);

            return(WithEntity(field) ?? View(
                       new GameRolesViewModel
            {
                ProjectId = field.Project.ProjectId,
                ProjectName = field.Project.ProjectName,
                CharacterGroupId = field.CharacterGroupId,
                ShowEditControls = field.HasEditRolesAccess(CurrentUserIdOrDefault),
                Data = CharacterGroupListViewModel.GetGroups(field, CurrentUserIdOrDefault)
            }));
        }
        public async Task <ActionResult> Index(int projectId, int?characterGroupId)
        {
            var field = await ProjectRepository.LoadGroupWithTreeAsync(projectId, characterGroupId);

            if (field == null)
            {
                return(HttpNotFound());
            }

            return(View(
                       new GameRolesViewModel
            {
                ProjectId = field.Project.ProjectId,
                ProjectName = field.Project.ProjectName,
                ShowEditControls = field.HasEditRolesAccess(CurrentUserIdOrDefault),
                HasMasterAccess = field.HasMasterAccess(CurrentUserIdOrDefault),
                Data = CharacterGroupListViewModel.GetGroups(field, CurrentUserIdOrDefault),
                Details = new CharacterGroupDetailsViewModel(field, CurrentUserIdOrDefault, GroupNavigationPage.Roles),
            }));
        }
        // GET: GameGroups
        public async Task <ActionResult> Report(int projectId, int?characterGroupId, int?maxDeep)
        {
            if (characterGroupId == null)
            {
                return(await RedirectToProject(projectId, "Report"));
            }

            ViewBag.MaxDeep = maxDeep ?? 1;

            var field = await ProjectRepository.LoadGroupWithTreeAsync(projectId, (int)characterGroupId);

            return(AsMaster(field) ?? View(
                       new GameRolesViewModel
            {
                ProjectId = field.Project.ProjectId,
                ProjectName = field.Project.ProjectName,
                CharacterGroupId = field.CharacterGroupId,
                ShowEditControls = field.HasEditRolesAccess(CurrentUserId),
                Data = CharacterGroupListViewModel.GetGroups(field, CurrentUserId)
            }));
        }
 private IEnumerable <CharacterViewModel> GetHotCharacters(CharacterGroup field)
 {
     return(CharacterGroupListViewModel.GetGroups(field, CurrentUserIdOrDefault)
            .SelectMany(
                g => g.PublicCharacters.Where(ch => ch.IsHot && ch.IsFirstCopy)).Distinct());
 }