Example #1
0
        public JsonNetResult GetAlertToEdit(string contentID)
        {
            try
            {
                var contentItemRequest = new GetContentItemRequest
                {
                    ContentItemIDs  = new[] { contentID },
                    SiteDescription = "Replicated"
                };
                // Return the first item from ContentItems with the contentID passed as param.
                var item = ContentService.GetAlert(contentItemRequest).FirstOrDefault();

                var contentItemCountryLanguagesRequest = new GetContentItemCountryLanguagesRequest
                {
                    ContentItemIDs = new[] { contentID }
                };
                // Return list of items from ContentItemCountryLanguages with the contentID of request.
                var countryLanguagePairs = ContentService.GetAlert(contentItemCountryLanguagesRequest);

                // Save content from first or default content found in ContentItemountryLanguages. We get the first one only because content is the same for all country/language pairs.
                var content = countryLanguagePairs.FirstOrDefault().Content;

                // Empty list of country/language pairs.
                var countryLanguagePairsValues = new List <string>();
                if (countryLanguagePairs != null)
                {
                    // Join country/Language and pass back to marketLanguagePairs List to be displayed in 'Market:'
                    foreach (var countrylanguagepair in countryLanguagePairs)
                    {
                        var market = GlobalSettings.Markets.AvailableMarkets.Where(c => c.CookieValue.ToString() == countrylanguagepair.CountryID).FirstOrDefault();
                        countryLanguagePairsValues.Add(market.CookieValue.ToString() + "/" + market.AvailableLanguages.Where(c => c.LanguageID == countrylanguagepair.LanguageID).FirstOrDefault().LanguageID.ToString());
                    }
                }

                // Return alert to be displayed, content, and country/language pairs.
                return(new JsonNetResult(new
                {
                    item,
                    content,
                    countryLanguagePairsValues,
                    success = true
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    error = ex.Message
                }));
            }
        }
Example #2
0
        /// <summary>
        /// Return cached version of a content block for a given country code and language.
        /// </summary>
        /// <param name="contentItemID">GUID</param>
        /// <param name="customerID">Used to check if user is Administrator to enable content block edit option.</param>
        /// <param name="currentCountry">User's current country.</param>
        /// <param name="selectedLanguage">User's selected language.</param>
        /// <returns></returns>
        public static HtmlString ContentBlock(string contentItemID, string siteDescription, string selectedLanguage, string currentCountry = "US", int customerTypeID = 0)
        {
            // Get the data and cache it.
            var    market   = GetContentMarket(currentCountry);
            var    language = GetContentLanguage(market, selectedLanguage);
            string cacheKey = contentItemID.ToUpper() + market.CookieValue + language.LanguageID.ToString();

            if (HttpRuntime.Cache[cacheKey] == null)
            {
                var contentItemRequest = new GetContentItemRequest
                {
                    ContentItemIDs  = new[] { contentItemID },
                    SiteDescription = siteDescription
                };
                var    item    = ContentService.GetContentBlock(contentItemRequest).FirstOrDefault();
                string content = null;
                // If content is available in contentItem table, we check in contentItemCountryLanguages
                if (item != null)
                {
                    var request = new GetContentItemCountryLanguagesRequest
                    {
                        ContentItemIDs = new[] { contentItemID },
                        CountryCode    = market.CookieValue,
                        LanguageID     = language.LanguageID,
                    };
                    content = ContentService.GetContentBlock(request).FirstOrDefault().Content.ToString();
                }
                if (content != null)
                {
                    HttpRuntime.Cache.Insert(cacheKey, content, null, DateTime.Now.AddMinutes(GlobalSettings.Exigo.CacheTimeout), Cache.NoSlidingExpiration);
                }
            }

            // Retrieve the cache.
            var data          = HttpRuntime.Cache[cacheKey];
            var cacheToString = data == null ? "Could not fetch data. Please try again later." : data.ToString();

            cacheToString = RenderViewSyntax(cacheToString, cacheKey);

            // Assembles content block container.
            string rawContentContainer = "<div class='cmcontent'>{0}</div>";

            // If we are content admin, wrap content block in html that allows edit.
            //if (customerTypeID == CustomerTypes.Master)
            if (customerTypeID == CustomerTypes.PreferredCustomer) // Ask Matt
            {
                rawContentContainer = "<div  id='" + contentItemID + "' class='cmcontentedit' data-toggle='modal' data-target='#editContent'><span class='glyphicon glyphicon-edit'></span>{0}</div><div style='clear: both'></div>".FormatWith(rawContentContainer);
            }

            // Return the formatted content.
            return(MvcHtmlString.Create(rawContentContainer.FormatWith(cacheToString)));
        }
Example #3
0
        public JsonNetResult GetContentItemContent(string contentID, string countryID, int languageID)
        {
            try
            {
                var request = new GetContentItemCountryLanguagesRequest
                {
                    ContentItemIDs = new[] { contentID },
                    CountryCode    = countryID,
                    LanguageID     = languageID
                };
                // Get content item py passing contentID and selected country/language.
                var contentBlock = ContentService.GetContentBlock(request).FirstOrDefault();

                // If contentBlock does not exist, we retreive default of US-en
                if (contentBlock == null)
                {
                    request.CountryCode = CountryCodes.UnitedStates;
                    request.LanguageID  = Languages.English;
                    contentBlock        = ContentService.GetContentBlock(request).FirstOrDefault();
                }

                if (contentBlock == null)
                {
                    throw new Exception("Could not fetch data. Please try again later.");
                }
                var content = ContentService.GetContentBlock(request).FirstOrDefault().Content;

                return(new JsonNetResult(new
                {
                    content,
                    success = true
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    error = ex.Message
                }));
            }
        }
Example #4
0
        public JsonNetResult FilterAlert()
        {
            try
            {
                var request = new GetContentItemRequest
                {
                    GetAlert        = true,
                    SiteDescription = "Replicated"
                };

                // Get a list of the alerts in the ContentItems table, filtered by expiration date and available date.
                List <ContentItem> contentList = ContentService.GetAlert(request);

                // If we did not returned alerts from the ContentItems table, we throw exception.
                if (!contentList.Any())
                {
                    return(new JsonNetResult(new
                    {
                        success = false,
                        message = "No alerts to display."
                    }));
                }

                // Get the country descripton and languageID of the current user.
                var currentCountry = GlobalSettings.Markets.AvailableMarkets
                                     .Where(c => c.CookieValue == Common.GlobalUtilities.GetSelectedCountryCode())
                                     .FirstOrDefault();
                var currentLanguageID = currentCountry.AvailableLanguages
                                        .Where(c => c.CultureCode == Exigo.GetSelectedLanguage())
                                        .FirstOrDefault()
                                        .LanguageID;

                // Else, we look for those alerts in the ContentItemCountryLanguages table.
                var alertFilterItem = new GetContentItemCountryLanguagesRequest
                {
                    CountryCode    = currentCountry.CookieValue,
                    LanguageID     = currentLanguageID,
                    ContentItemIDs = contentList.Select(c => c.ContentItemID.ToString()).ToArray(),
                    ContentItems   = contentList
                };

                var filteredContentList = ContentService.GetAlert(alertFilterItem);

                // If we did not returned alerts from the ContentItemCountryLanguages table, we throw exception.
                if (!filteredContentList.Any())
                {
                    throw new Exception("No alerts to display.");
                }

                // Else, we display the most recent alert.
                var alertToDisplay = filteredContentList.Where(x => x.ContentItemID == contentList.OrderByDescending(c => c.ValidFrom).FirstOrDefault().ContentItemID).FirstOrDefault();

                return(new JsonNetResult(new
                {
                    success = true,
                    alertToDisplay
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    error = ex.Message
                }));
            }
        }