Esempio n. 1
0
        public static CharacterNavigationViewModel FromClaim([NotNull]
                                                             Claim claim,
                                                             int currentUserId,
                                                             CharacterNavigationPage characterNavigationPage)
        {
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }
            var vm = new CharacterNavigationViewModel
            {
                CanAddClaim     = false,
                ClaimId         = claim.ClaimId,
                HasMasterAccess = claim.HasMasterAccess(currentUserId),
                CharacterId     = claim.Character?.CharacterId,
                ProjectId       = claim.ProjectId,
                Page            = characterNavigationPage,
                Name            = claim.GetTarget().Name,
                CanEditRoles    = claim.HasEditRolesAccess(currentUserId),
                IsActive        = claim.GetTarget().IsActive,
            };

            vm.LoadClaims(claim.Character);
            if (vm.RejectedClaims.Any(c => c.ClaimId == claim.ClaimId))
            {
                vm.Page    = CharacterNavigationPage.RejectedClaim;
                vm.ClaimId = null;
            }

            return(vm);
        }
Esempio n. 2
0
        public static CharacterNavigationViewModel FromCharacter(Character character,
                                                                 CharacterNavigationPage page,
                                                                 int?currentUserId)
        {
            int?claimId;

            if (character.ApprovedClaim?.HasAccess(currentUserId, ExtraAccessReason.Player) == true
                ) //If Approved Claim exists and we have access to it, so be it.
            {
                claimId = character.ApprovedClaim.ClaimId;
            }
            else // if we have My claims, try select single one. We may fail to do so.
            {
                claimId = character.Claims.Where(c => c.PlayerUserId == currentUserId)
                          .TrySelectSingleClaim()?.ClaimId;
            }

            var vm = new CharacterNavigationViewModel
            {
                CanAddClaim     = character.IsAvailable,
                ClaimId         = claimId,
                HasMasterAccess = character.HasMasterAccess(currentUserId),
                CanEditRoles    = character.HasEditRolesAccess(currentUserId),
                CharacterId     = character.CharacterId,
                ProjectId       = character.ProjectId,
                Page            = page,
                Name            = character.CharacterName,
                IsActive        = character.IsActive,
            };

            vm.LoadClaims(character);
            return(vm);
        }