public JsonNetResult GetAlertList() { try { // New, empty model. var model = new ContentListModel(); // New AlertItem object with GetAllAlerts boolean set to true. var request = new GetContentItemRequest { SiteDescription = "Replicated", GetAllAlerts = true }; // Get all alerts from ContentItems table and store them in ContentList of model. model.ContentList = ContentService.GetAlert(request); // Pass model to partial and return as html string. var html = this.RenderPartialViewToString("partials/_alertlist", model); return(new JsonNetResult(new { success = true, html = html, })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, error = ex.Message })); } }
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 })); } }
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 })); } }