Esempio n. 1
0
        public static ValueList FilterNullList(ValueList list)
        {
            var elementType = ((AttributeTypeCollection)list.AttributeType).ElementType;

            if (!list.Any())
            {
                return(list);
            }
            var result = list.Where(v => !v.IsNull).ToList();

            return(new ValueList(result.Any() ? result : null, elementType));
        }
        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);
        }