private void LoadImageFieldsToDb()
        {
            List <TitleFields> titleFieldsList;
            List <ImageFields> imageFieldsList = new List <ImageFields>();
            string             remoteUrlBase   = _config["RemoteImageUrl"];

            titleFieldsList = _imageRepository.GetTitleFields();

            foreach (TitleFields title in titleFieldsList)
            {
                ImageFields image = new ImageFields
                {
                    ArtKey  = title.ArtKey,
                    AltText = title.Title
                };

                image.RemoteUrl = $"{ remoteUrlBase }{ title.ArtKey }_270.jpeg";

                imageFieldsList.Add(image);
            }

            bool imagesInserted = _imageRepository.CreateImageFields(imageFieldsList);

            if (imagesInserted == true)
            {
                _log.LogInformation("Image records inserted into the database");
            }
        }
Example #2
0
        static ImageFields GetImageFields(string value, FieldSetting setting, int portalId)
        {
            var strFieldvalue = value;
            var url           = string.Empty;
            var imageUrl      = string.Empty;
            var path          = string.Empty;

            if (strFieldvalue != string.Empty)
            {
                if (strFieldvalue.StartsWith("http:") || strFieldvalue.StartsWith("https:"))
                {
                    imageUrl = strFieldvalue;
                    url      = imageUrl;
                }
                else
                {
                    var fileInfo = strFieldvalue.StartsWith("FileID=")
                                       ? FileManager.Instance.GetFile(int.Parse(UrlUtils.GetParameterValue(strFieldvalue)))
                                       : FileManager.Instance.GetFile(portalId, strFieldvalue);
                    if (fileInfo != null)
                    {
                        imageUrl = FileManager.Instance.GetUrl(fileInfo);
                        path     = Path.Combine(fileInfo.Folder, fileInfo.FileName);
                    }
                    var parms = "";
                    if (setting.Width > 0)
                    {
                        parms = string.Format("{0}&w={1}", parms, setting.Width);
                    }
                    if (setting.Height > 0)
                    {
                        parms = string.Format("{0}&h={1}", parms, setting.Height);
                    }
                    if (parms != "")
                    {
                        url = string.Format("{0}?image={1}{2}&PortalId={3}",
                                            Globals.ResolveUrl(string.Format("~{0}MakeThumbnail.ashx",
                                                                             Definition.PathOfModule)),
                                            HttpUtility.UrlEncode(path), parms,
                                            portalId);
                    }
                    else
                    {
                        url = imageUrl;
                    }
                }

                url = HttpUtility.HtmlEncode(url);
                if (setting.AsLink)
                {
                    strFieldvalue =
                        string.Format(
                            "<a href=\"{0}\" target=\"_blank\"><img alt=\"{1}\" title=\"{1}\" border=\"0\" src=\"{2}\" /></a>",
                            imageUrl, "{0}", url);
                }
                else
                {
                    strFieldvalue = string.Format("<img alt=\"{0}\" title=\"{0}\" src=\"{1}\" />", "{0}",
                                                  url);
                }
            }
            var imageFields = new ImageFields
            {
                Value = strFieldvalue,

                Original = value,
                Url      = url
            };

            return(imageFields);
        }
Example #3
0
 static ImageFields GetImageFields(string value, FieldSetting setting, int portalId)
 {
     var strFieldvalue = value;
     var url = string.Empty;
     var imageUrl = string.Empty;
     var path = string.Empty;
     if (strFieldvalue != string.Empty)
     {
         if (strFieldvalue.StartsWith("http:") || strFieldvalue.StartsWith("https:"))
         {
             imageUrl = strFieldvalue;
             url = imageUrl;
         }
         else
         {
             var fileInfo = strFieldvalue.StartsWith("FileID=")
                                ? FileManager.Instance.GetFile(int.Parse(UrlUtils.GetParameterValue(strFieldvalue)))
                                : FileManager.Instance.GetFile(portalId, strFieldvalue);
             if (fileInfo != null)
             {
                 imageUrl = FileManager.Instance.GetUrl(fileInfo);
                 path = Path.Combine(fileInfo.Folder, fileInfo.FileName);
             }
             var parms = "";
             if (setting.Width > 0)
             {
                 parms = string.Format("{0}&w={1}", parms, setting.Width);
             }
             if (setting.Height > 0)
             {
                 parms = string.Format("{0}&h={1}", parms, setting.Height);
             }
             if (parms != "")
             {
                 url = string.Format("{0}?image={1}{2}&PortalId={3}",
                                     Globals.ResolveUrl(string.Format("~{0}MakeThumbnail.ashx",
                                                                      Definition.PathOfModule)),
                                     HttpUtility.UrlEncode(path), parms,
                                     portalId);
             }
             else
             {
                 url = imageUrl;
             }
         }
       
         url = HttpUtility.HtmlEncode(url);
         if (setting.AsLink)
         {
             strFieldvalue =
                 string.Format(
                     "<a href=\"{0}\" target=\"_blank\"><img alt=\"{1}\" title=\"{1}\" border=\"0\" src=\"{2}\" /></a>",
                     imageUrl, "{0}", url);
         }
         else
         {
             strFieldvalue = string.Format("<img alt=\"{0}\" title=\"{0}\" src=\"{1}\" />", "{0}",
                                           url);
         }
     }
     var imageFields = new ImageFields
                           {
                               Value = strFieldvalue,
                              
                               Original = value,
                               Url = url
                           };
     return imageFields;
 }