Ejemplo n.º 1
0
        public ClaimListItemViewModel([NotNull] Claim claim, int currentUserId)
        {
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }
            var lastComment = claim.Comments.Where(c => c.IsVisibleToPlayer).OrderByDescending(c => c.CommentId).FirstOrDefault();

            ClaimId     = claim.ClaimId;
            ClaimStatus = (ClaimStatusView)claim.ClaimStatus;
            Name        = claim.Name;
            Player      = claim.Player;

            UpdateDate          = lastComment?.LastEditTime ?? claim.CreateDate;
            CreateDate          = claim.CreateDate;
            Responsible         = claim.ResponsibleMasterUser;
            LastModifiedBy      = lastComment?.Author ?? claim.Player;
            UnreadCommentsCount =
                claim.Comments.Count(comment => (comment.IsVisibleToPlayer || claim.HasMasterAccess(currentUserId)) &&
                                     !comment.IsReadByUser(currentUserId));

            ProjectId   = claim.ProjectId;
            ProjectName = claim.Project.ProjectName;
            Fields      = new CustomFieldsViewModel(currentUserId, claim);
            FeePaid     = claim.ClaimBalance();
            FeeDue      = claim.ClaimFeeDue();
        }
Ejemplo n.º 2
0
        public FieldValueViewModel(CustomFieldsViewModel model, [NotNull] FieldWithValue ch, ILinkRenderer renderer)
        {
            if (ch == null)
            {
                throw new ArgumentNullException(nameof(ch));
            }

            Value = ch.Value;

            if (ch.Field.SupportsMarkdown())
            {
                DisplayString = new MarkdownString(ch.DisplayString).ToHtmlString(renderer);
            }
            else
            {
                DisplayString = ch.DisplayString.SanitizeHtml();
            }
            FieldViewType = (ProjectFieldViewType)ch.Field.FieldType;
            FieldName     = ch.Field.FieldName;
            Description   = ch.Field.Description.ToHtmlString();

            IsPlayerVisible = ch.Field.CanPlayerView;
            IsDeleted       = !ch.Field.IsActive;

            HasValue = ch.HasValue || !ch.Field.CanHaveValue();

            var hasViewAccess = ch.Field.IsPublic ||
                                model.HasMasterAccess
                                ||
                                (model.HasPlayerAccessToCharacter && ch.Field.CanPlayerView &&
                                 ch.Field.FieldBoundTo == FieldBoundTo.Character)
                                ||
                                (model.HasPlayerClaimAccess && ch.Field.CanPlayerView &&
                                 ch.Field.FieldBoundTo == FieldBoundTo.Claim);

            CanView = hasViewAccess &&
                      (ch.HasValue || (!ch.Field.CanHaveValue() && ch.Field.IsAvailableForTarget(model.Target)));

            CanEdit = model.EditAllowed &&
                      ch.HasEditAccess(
                model.HasMasterAccess,
                model.HasPlayerAccessToCharacter,
                model.HasPlayerClaimAccess,
                model.Target);

            if (ch.Field.HasValueList())
            {
                ValueList         = ch.GetDropdownValues().ToArray();
                PossibleValueList = ch.GetPossibleValues();
            }
            ProjectFieldId = ch.Field.ProjectFieldId;

            FieldBound      = (FieldBoundToViewModel)ch.Field.FieldBoundTo;
            MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus;
        }
Ejemplo n.º 3
0
 public AddClaimViewModel Fill(IClaimSource obj, User user)
 {
     ProjectId        = obj.ProjectId;
     ProjectName      = obj.Project.ProjectName;
     HasAnyClaim      = user.Claims.Any(c => c.ProjectId == obj.ProjectId && c.IsPending);
     HasApprovedClaim = !(obj.Project.Details?.EnableManyCharacters ?? false) && obj.Project.Claims.OfUserApproved(user.UserId).Any();
     HasMyClaim       = obj.HasClaimForUser(user.UserId);
     TargetName       = obj.Name;
     Description      = obj.Description.ToHtmlString();
     IsAvailable      = obj.IsAvailable;
     ClaimApplyRules  = obj.Project.Details?.ClaimApplyRules.ToHtmlString();
     Fields           = new CustomFieldsViewModel(user.UserId, obj);
     IsRoot           = obj.IsRoot;
     return(this);
 }
Ejemplo n.º 4
0
        public FieldValueViewModel(
            CustomFieldsViewModel model,
            [NotNull] FieldWithValue ch,
            ILinkRenderer renderer)
        {
            if (ch == null)
            {
                throw new ArgumentNullException(nameof(ch));
            }

            Value = ch.Value;

            DisplayString = ch.Field.SupportsMarkdown()
        ? new MarkdownString(ch.DisplayString).ToHtmlString(renderer)
        : ch.DisplayString.SanitizeHtml();
            FieldViewType = (ProjectFieldViewType)ch.Field.FieldType;
            FieldName     = ch.Field.FieldName;
            Description   = ch.Field.Description.ToHtmlString();

            IsPlayerVisible = ch.Field.CanPlayerView;
            IsDeleted       = !ch.Field.IsActive;

            HasValue = ch.HasViewableValue;

            var hasViewAccess = ch.HasViewableValue &&
                                ch.HasViewAccess(model.AccessArguments);

            CanView = hasViewAccess && (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));

            CanEdit = model.EditAllowed &&
                      ch.HasEditAccess(model.AccessArguments, model.Target) &&
                      (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));

            //if not "HasValues" types, will be empty
            ValueList         = ch.GetDropdownValues().Select(v => new FieldPossibleValueViewModel(v)).ToArray();
            PossibleValueList = ch.GetPossibleValues().Select(v => new FieldPossibleValueViewModel(v)).ToList();

            ProjectFieldId = ch.Field.ProjectFieldId;

            FieldBound      = (FieldBoundToViewModel)ch.Field.FieldBoundTo;
            MandatoryStatus = IsDeleted ? MandatoryStatusViewType.Optional : (MandatoryStatusViewType)ch.Field.MandatoryStatus;

            ProjectId = ch.Field.ProjectId;
        }
Ejemplo n.º 5
0
        public AddClaimViewModel Fill(IClaimSource claimSource, int playerUserId)
        {
            var disallowReasons = claimSource.ValidateIfCanAddClaim(playerUserId)
                                  .Select(x => x.ToViewModel()).ToList();

            CanSendClaim = !disallowReasons.Any();

            IsProjectRelatedReason = disallowReasons.Intersect(new[]
            {
                AddClaimForbideReasonViewModel.ProjectClaimsClosed,
                AddClaimForbideReasonViewModel.ProjectNotActive,
            })
                                     .Any();



            if (!disallowReasons.Any())
            {
                var myClaims = claimSource.Project.Claims.OfUserActive(playerUserId);
                if (myClaims.Any())
                {
                    disallowReasons.Add(AddClaimForbideReasonViewModel
                                        .AlredySentNotApprovedClaimToAnotherPlace);
                }
            }

            ValidationStatus = disallowReasons;
            ProjectAllowsMultipleCharacters = claimSource.Project.Details.EnableManyCharacters;

            ProjectId       = claimSource.Project.ProjectId;
            ProjectName     = claimSource.Project.ProjectName;
            TargetName      = claimSource.Name;
            Description     = claimSource.Description.ToHtmlString();
            IsAvailable     = claimSource.IsAvailable;
            ClaimApplyRules = claimSource.Project.Details.ClaimApplyRules.ToHtmlString();
            Fields          = new CustomFieldsViewModel(playerUserId, claimSource);
            IsRoot          = claimSource.IsRoot;
            return(this);
        }
Ejemplo n.º 6
0
        public ClaimViewModel(User currentUser,
                              Claim claim,
                              IEnumerable <PluginOperationData <IPrintCardPluginOperation> > pluginOperationDatas,
                              IReadOnlyCollection <PlotElement> plotElements,
                              IUriService uriService,
                              IEnumerable <ProjectAccommodationType> availableAccommodationTypes = null,
                              IEnumerable <AccommodationRequest> accommodationRequests           = null,
                              IEnumerable <AccommodationPotentialNeighbors> potentialNeighbors   = null,
                              IEnumerable <AccommodationInvite> incomingInvite = null,
                              IEnumerable <AccommodationInvite> outgoingInvite = null)
        {
            ClaimId             = claim.ClaimId;
            CommentDiscussionId = claim.CommentDiscussionId;
            RootComments        = claim.CommentDiscussion.ToCommentTreeViewModel(currentUser.UserId);
            HasMasterAccess     = claim.HasMasterAccess(currentUser.UserId);
            CanManageThisClaim  = claim.HasAccess(currentUser.UserId,
                                                  acl => acl.CanManageClaims,
                                                  ExtraAccessReason.ResponsibleMaster);
            CanChangeRooms = claim.HasAccess(currentUser.UserId,
                                             acl => acl.CanSetPlayersAccommodations,
                                             ExtraAccessReason.PlayerOrResponsible);
            IsMyClaim                   = claim.PlayerUserId == currentUser.UserId;
            Player                      = claim.Player;
            ProjectId                   = claim.ProjectId;
            ProjectName                 = claim.Project.ProjectName;
            Status                      = new ClaimFullStatusView(claim, new AccessArguments(claim, currentUser.UserId));
            CharacterGroupId            = claim.CharacterGroupId;
            GroupName                   = claim.Group?.CharacterGroupName;
            CharacterId                 = claim.CharacterId;
            CharacterActive             = claim.Character?.IsActive;
            CharacterAutoCreated        = claim.Character?.AutoCreated;
            AvailableAccommodationTypes = availableAccommodationTypes?.Where(a =>
                                                                             a.IsPlayerSelectable || a.Id == claim.AccommodationRequest?.AccommodationTypeId ||
                                                                             claim.HasMasterAccess(currentUser.UserId)).ToList();
            PotentialNeighbors               = potentialNeighbors;
            AccommodationRequest             = claim.AccommodationRequest;
            IncomingInvite                   = incomingInvite;
            OutgoingInvite                   = outgoingInvite;
            OtherClaimsForThisCharacterCount = claim.IsApproved
              ? 0
              : claim.OtherClaimsForThisCharacter().Count();
            HasOtherApprovedClaim = !claim.IsApproved &&
                                    claim.OtherClaimsForThisCharacter().Any(c => c.IsApproved);
            Data = new CharacterTreeBuilder(claim.Project.RootGroup, currentUser.UserId).Generate();
            OtherClaimsFromThisPlayerCount     =
                OtherClaimsFromThisPlayerCount =
                    claim.IsApproved || claim.Project.Details.EnableManyCharacters
                      ? 0
                      : claim.OtherPendingClaimsForThisPlayer().Count();
            Masters =
                claim.Project.GetMasterListViewModel()
                .Union(new MasterListItemViewModel()
            {
                Id = "-1", Name = "Нет"
            });
            ResponsibleMasterId = claim.ResponsibleMasterUserId ?? -1;
            ResponsibleMaster   = claim.ResponsibleMasterUser;
            Fields     = new CustomFieldsViewModel(currentUser.UserId, claim);
            Navigation =
                CharacterNavigationViewModel.FromClaim(claim,
                                                       currentUser.UserId,
                                                       CharacterNavigationPage.Claim);
            ClaimFee      = new ClaimFeeViewModel(claim, this, currentUser.UserId);
            Problems      = claim.GetProblems().Select(p => new ProblemViewModel(p)).ToList();
            PlayerDetails = new UserProfileDetailsViewModel(claim.Player,
                                                            (AccessReason)claim.Player.GetProfileAccess(currentUser));
            PrintPlugins         = pluginOperationDatas.Select(PluginOperationDescriptionViewModel.Create);
            ProjectActive        = claim.Project.Active;
            CheckInStarted       = claim.Project.Details.CheckInProgress;
            CheckInModuleEnabled = claim.Project.Details.EnableCheckInModule;
            Validator            = new ClaimCheckInValidator(claim);

            AccommodationEnabled = claim.Project.Details.EnableAccommodation;

            if (claim.HasAccess(currentUser.UserId,
                                acl => acl.CanManageMoney, ExtraAccessReason.Player))
            {
                //Finance admins can create any payment. User also can create any payment, but it will be moderated
                PaymentTypes = claim.Project.ActivePaymentTypes;
            }
            else
            {
                //All other master can create only payment from user to himself.
                PaymentTypes =
                    claim.Project.ActivePaymentTypes.Where(pt => pt.UserId == currentUser.UserId);
            }


            if (claim.Character != null)
            {
                ParentGroups = new CharacterParentGroupsViewModel(claim.Character,
                                                                  claim.HasMasterAccess(currentUser.UserId));
            }

            if (claim.IsApproved && claim.Character != null)
            {
                var readOnlyList = claim.Character.GetOrderedPlots(plotElements);
                Plot = PlotDisplayViewModel.Published(readOnlyList,
                                                      currentUser.UserId,
                                                      claim.Character,
                                                      uriService);
            }
            else
            {
                Plot = PlotDisplayViewModel.Empty();
            }
        }
Ejemplo n.º 7
0
        public ClaimViewModel(int currentUserId, Claim claim, IEnumerable <PluginOperationData <IPrintCardPluginOperation> > pluginOperationDatas, IReadOnlyCollection <PlotElement> plotElements)
        {
            ClaimId  = claim.ClaimId;
            Comments =
                claim.Comments.Where(comment => comment.ParentCommentId == null)
                .Select(comment => new CommentViewModel(comment, currentUserId)).OrderBy(c => c.CreatedTime);
            HasMasterAccess    = claim.HasMasterAccess(currentUserId);
            CanManageThisClaim = claim.CanManageClaim(currentUserId);
            IsMyClaim          = claim.PlayerUserId == currentUserId;
            Player             = claim.Player;
            ProjectId          = claim.ProjectId;
            Status             = claim.ClaimStatus;
            CharacterGroupId   = claim.CharacterGroupId;
            GroupName          = claim.Group?.CharacterGroupName;
            CharacterId        = claim.CharacterId;
            CharacterActive    = claim.Character?.IsActive;
            OtherClaimsForThisCharacterCount = claim.IsApproved ? 0 : claim.OtherClaimsForThisCharacter().Count();
            HasOtherApprovedClaim            = !claim.IsApproved && claim.OtherClaimsForThisCharacter().Any(c => c.IsApproved);
            Data = new CharacterTreeBuilder(claim.Project.RootGroup, currentUserId).Generate();
            OtherClaimsFromThisPlayerCount     =
                OtherClaimsFromThisPlayerCount = claim.IsApproved || (claim.Project.Details?.EnableManyCharacters ?? false)
          ? 0
          : claim.OtherPendingClaimsForThisPlayer().Count();
            Description = claim.Character?.Description.ToHtmlString();
            Masters     =
                claim.Project.GetMasterListViewModel()
                .Union(new MasterListItemViewModel()
            {
                Id = "-1", Name = "Нет"
            });
            ResponsibleMasterId = claim.ResponsibleMasterUserId ?? -1;
            ResponsibleMaster   = claim.ResponsibleMasterUser;
            Fields        = new CustomFieldsViewModel(currentUserId, claim);
            Navigation    = CharacterNavigationViewModel.FromClaim(claim, currentUserId, CharacterNavigationPage.Claim);
            ClaimFee      = new ClaimFeeViewModel(claim, currentUserId);
            Problems      = claim.GetProblems().Select(p => new ProblemViewModel(p)).ToList();
            PlayerDetails = UserProfileDetailsViewModel.FromUser(claim.Player);
            PrintPlugins  = pluginOperationDatas.Select(PluginOperationDescriptionViewModel.Create);
            ProjectActive = claim.Project.Active;

            if (claim.PlayerUserId == currentUserId || claim.HasMasterAccess(currentUserId, acl => acl.CanManageMoney))
            {
                //Finance admins can create any payment. User also can create any payment, but it will be moderated
                PaymentTypes = claim.Project.ActivePaymentTypes;
            }
            else
            {
                //All other master can create only payment from user to himself.
                PaymentTypes = claim.Project.ActivePaymentTypes.Where(pt => pt.UserId == currentUserId);
            }


            if (claim.Character != null)
            {
                ParentGroups = new CharacterParentGroupsViewModel(claim.Character,
                                                                  claim.HasMasterAccess(currentUserId));
            }

            Plot = claim.IsApproved && claim.Character != null
        ? claim.Character.GetOrderedPlots(plotElements).ToViewModels(currentUserId, claim.Character)
        : Enumerable.Empty <PlotElementViewModel>();
        }
        public FieldValueViewModel(
            CustomFieldsViewModel model,
            [NotNull] FieldWithValue ch,
            ILinkRenderer renderer)
        {
            if (ch == null)
            {
                throw new ArgumentNullException(nameof(ch));
            }

            Value = ch.Value;

            DisplayString = ch.Field.SupportsMarkdown()
                ? new MarkdownString(ch.DisplayString).ToHtmlString(renderer)
                : ch.DisplayString.SanitizeHtml();
            FieldViewType = (ProjectFieldViewType)ch.Field.FieldType;
            FieldName     = ch.Field.FieldName;

            HasMasterAccess = model.AccessArguments.MasterAccess;
            Description     = ch.Field.Description.ToHtmlString();

            MasterDescription = HasMasterAccess ? ch.Field.MasterDescription.ToHtmlString() : "".MarkAsHtmlString();

            IsPlayerVisible = ch.Field.CanPlayerView;
            IsDeleted       = !ch.Field.IsActive;

            HasValue = ch.HasViewableValue;

            CanView = ch.HasViewableValue &&
                      ch.HasViewAccess(model.AccessArguments) &&
                      (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));

            CanEdit = model.EditAllowed &&
                      ch.HasEditAccess(model.AccessArguments) &&
                      (ch.HasEditableValue || ch.Field.IsAvailableForTarget(model.Target));


            // Detecting if field (or its values) has a price or not
            HasPrice = ch.SupportsPricing();

            //if not "HasValues" types, will be empty
            ValueList = ch.GetDropdownValues()
                        .Select(v => new FieldPossibleValueViewModel(v, HasPrice, true)).ToList();
            PossibleValueList = ch.GetPossibleValues(model.AccessArguments).Select(v => new FieldPossibleValueViewModel(v,
                                                                                                                        HasPrice,
                                                                                                                        ValueList.Any(sv =>
                                                                                                                                      sv.ProjectFieldDropdownValueId == v.ProjectFieldDropdownValueId)))
                                .ToArray();

            if (HasPrice)
            {
                if (FieldViewType.SupportsPricingOnField())
                {
                    Price = ch.Field.Price;
                }

                Fee = ch.GetCurrentFee();
            }

            ShowPrice = HasPrice && model.AccessArguments.AnyAccessToClaim;

            ProjectFieldId = ch.Field.ProjectFieldId;

            FieldBound      = (FieldBoundToViewModel)ch.Field.FieldBoundTo;
            MandatoryStatus = IsDeleted
                ? MandatoryStatusViewType.Optional
                : (MandatoryStatusViewType)ch.Field.MandatoryStatus;

            ProjectId = ch.Field.ProjectId;

            SetFieldLabels(ch);
        }