public static List <string> GetImageUrls(this IFieldFramework fields, FileService fileService, Func <int, ImageSize> getImageSize = null)
        {
            if (fields == null)
            {
                return(null);
            }

            var imageIds = (fields[SystemFieldDefinitionConstants.Images] as IReadOnlyCollection <Guid>)?.ToArray();

            if (imageIds?.Length > 0)
            {
                var result = new List <string>();
                for (int i = 0; i < imageIds.Length; i++)
                {
                    ImageSize imageSize = null;
                    if (getImageSize != null)
                    {
                        imageSize = getImageSize(i);
                    }
                    var file = fileService.Get(imageIds[i]);
                    var link = (imageSize != null)
                        ? file.GetUrlToImage(imageSize.MaxSize, imageSize.MinSize, out Size actualSize, false)
                        : file.GetUrlToImage(out actualSize, false);

                    result.Add(link);
                }
                return(result);
            }
            else
            {
                return(null);
            }
        }
        public static string GetDescription(this IFieldFramework fields, string culture)
        {
            if (fields == null || string.IsNullOrWhiteSpace(culture))
            {
                return(null);
            }

            return(fields[SystemFieldDefinitionConstants.Description, culture] as string);
        }
Beispiel #3
0
        public void AddProperties <TArea>(StructureInfo structureInfo, IFieldFramework oldFieldContainer, IFieldFramework fieldContainer, bool changeUrl = true, IList <string> excludeFields = null)
            where TArea : IArea
        {
            if (oldFieldContainer[SystemFieldDefinitionConstants.Images] is List <Guid> images)
            {
                var newImages = images.Select(structureInfo.Id).ToList();

                fieldContainer[SystemFieldDefinitionConstants.Images] = newImages;
            }

            var fields = Get <TArea>((IFieldContainerAccessor)oldFieldContainer);

            foreach (var field in fields)
            {
                if (excludeFields?.Contains(field.Key) == true)
                {
                    continue;
                }

                var fieldDefinition = _fieldDefinitionService.Get <TArea>(field.Key);
                if (fieldDefinition == null)
                {
                    continue;
                }

                if (fieldDefinition.MultiCulture)
                {
                    foreach (var cultureValue in field.Value)
                    {
                        var value = CorrectValue <TArea>(structureInfo, field.Key, cultureValue.Value, fieldDefinition, changeUrl);
                        fieldContainer[fieldDefinition.Id, cultureValue.Key] =
                            ConvertFromEditValue(
                                new EditFieldTypeConverterArgs(fieldDefinition, new CultureInfo(cultureValue.Key)),
                                value);
                    }
                }
                else
                {
                    if (field.Value.TryGetValue("*", out var value))
                    {
                        var newValue = CorrectValue <TArea>(structureInfo, field.Key, value, fieldDefinition, changeUrl);
                        fieldContainer[fieldDefinition.Id] =
                            ConvertFromEditValue(
                                new EditFieldTypeConverterArgs(fieldDefinition, CultureInfo.CurrentCulture), newValue);
                    }
                    else
                    {
                        fieldContainer.TryRemoveValue(fieldDefinition.Id, out _);
                    }
                }
            }
        }
        public static List <string> GetImageUrls(this IFieldFramework fields, Func <int, ImageSize> getImageSize = null)
        {
            if (fields == null)
            {
                return(null);
            }

            var imageIds = (fields[SystemFieldDefinitionConstants.Images] as IReadOnlyCollection <Guid>)?.ToArray();

            if (imageIds?.Length > 0)
            {
                var result = new List <string>();
                for (int i = 0; i < imageIds.Length; i++)
                {
                    ImageSize imageSize = null;
                    if (getImageSize != null)
                    {
                        imageSize = getImageSize(i);
                    }
                    var file = imageIds[i].MapTo <ImageModel>();
                    var link = (imageSize != null)
                        ? file.GetUrlToImage(imageSize.MinSize, imageSize.MaxSize)
                        : file.GetUrlToImage(default, default);
 public static string GetColor(this IFieldFramework fields)
 {
     return(fields[FieldDefinitionConstantColor] as string);
 }