Exemple #1
0
        public IEnumerable <Data.Items.Item> filterDiningPrivileges(IEnumerable <Data.Items.Item> items, string _penawaran, string id)
        {
            if (_penawaran.ToLower() == id.ToLower())
            {
                _penawaran = string.Empty;
            }
            Sitecore.Data.Items.Item dataSourceItem = Sitecore.Context.Database.GetItem(new Data.ID(id));
            if (String.IsNullOrEmpty(_penawaran))
            {
                Sitecore.Data.Items.Item            ItemLocationPromotion     = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.LocationPromotion.ID).FirstOrDefault();
                Sitecore.Data.Fields.MultilistField SelectedLocationPromotion = ItemLocationPromotion.Fields[Sitecore.Feature.Library.Templates.LocationPromotion.Fields.Location];
                if (SelectedLocationPromotion.GetItems().Count() > 0)
                {
                    //Sitecore.Data.Items.Item defaultSelectedCountry = SelectedLocationPromotion.GetItems().FirstOrDefault();
                    //items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(defaultSelectedCountry.ID.ToString().ToLower()));
                    items = items.Where(x => SelectedLocationPromotion.GetItems().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(y.ID.ToString().ToLower())));
                }
            }
            else
            {
                items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(_penawaran.ToLower()));
            }

            items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.Layout].Value.ToLower().Contains(dataSourceItem.ID.ToString().ToLower()));

            return(items);
        }
Exemple #2
0
        public IEnumerable <Data.Items.Item> filterItemBelanjaOnline(IEnumerable <Data.Items.Item> items, string _category, string id)
        {
            Sitecore.Data.Items.Item dataSourceItem = Sitecore.Context.Database.GetItem(new Data.ID(id));

            if (!String.IsNullOrEmpty(_category))
            {
                items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(_category.ToLower()));
            }
            else
            {
                Sitecore.Data.Items.Item ItemProductCategory = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.ListCategoryPromotion.ID).FirstOrDefault();
                if (ItemProductCategory != null)
                {
                    Sitecore.Data.Fields.MultilistField oItemProductCategory = ItemProductCategory.Fields[Sitecore.Feature.Library.Templates.ListCategoryPromotion.Fields.Category];
                    if (oItemProductCategory.GetItems().Count() > 0)
                    {
                        string[] idCategories = oItemProductCategory.GetItems().Select(x => x.ID.ToString().ToLower()).ToArray();
                        items = items.Where(x => idCategories.Where(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(y.ToLower())).Any());
                    }
                }
            }

            items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.Layout].Value.ToLower().Contains(dataSourceItem.ID.ToString().ToLower()));

            return(items);
        }
Exemple #3
0
        static public List <Item> GetListItems(this Item item, ID fieldId)
        {
            Sitecore.Data.Fields.MultilistField mlf = GetField(item, fieldId);

            if (mlf != null && mlf.Count > 0)
            {
                return(mlf.GetItems().ToList());
            }

            return(new List <Item>());
        }
        /// <summary>
        /// OnLoad event.  Override the OnLoad event to inject our DataSourceField 
        /// when the selected value of the data source field changes.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            Item parentItem = null;
            string fundComponentName = string.Empty;

            if (!Sitecore.Context.ClientPage.IsEvent)
            {
                var fieldValue = ConfigurationManager.AppSettings[CMSConstants.ComponentItemGUID];
                var db = GetDatabase();
                var includeTemplates = HttpUtility.HtmlDecode(GetTypeIncludeTemplates());
                Sitecore.Data.Items.Item[] labelItems = null;
                Sitecore.Data.Fields.MultilistField components = null;
                parentItem = CurrentItem().Parent;
                if (labelItems != null)
                {
                    foreach (Item labelItem in labelItems)
                    {
                        components = (Sitecore.Data.Fields.MultilistField)labelItem.Fields["ComponentName"];
                        if (components != null && components.List != null && parentItem != null && parentItem.Fields["Content Type"] != null && !string.IsNullOrEmpty(parentItem.Fields["Content Type"].Value) && components.List.ToString().Contains(parentItem.Fields["Content Type"].Value))
                        {
                            sbItemId.Append("@@id='" + labelItem.ID + "'").Append(" or ");
                        }
                    }
                }
                if (IsPathOrGuid(fieldValue) && !SourceContainsDataSource())
                {
                    var sourceItem = ResolveItem(fieldValue);
                    if (sourceItem != null)
                    {
                        if (sbItemId.Length > 80)
                            base.Source = sbItemId.ToString().Remove(sbItemId.Length - 4, 4) + "]";
                        else
                            base.Source = string.Empty;
                        base.Value = SanitizeValues(sourceItem, parentItem, labelItems, Value);
                    }
                    hasValidSource = true;
                }
            }
            if (Sitecore.Context.ClientPage.IsEvent)
            {
                string str = Sitecore.Context.ClientPage.ClientRequest.Form[this.ID + "_value"];
                if (str != null)
                {
                    if (base.GetViewStateString("Value", string.Empty) != str)
                    {
                    }
                    base.SetViewStateString("Value", str);
                }
            }
            base.OnLoad(e);
        }
        /// <summary>
        /// Previous Years Snapshot Section
        /// </summary>
        /// <returns></returns>
        public ActionResult RenderPastYearSnapshotSection()
        {
            var currentItem  = RenderingContext.Current.Rendering.Item;
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var dataSource   = Sitecore.Context.Database.GetItem(dataSourceId);

            if (dataSource != null)
            {
                var previousyearinformation = dataSource.Fields["PreviousYearSnapshotTitle"]?.Value;
                Sitecore.Data.Fields.MultilistField multiselectField =
                    dataSource.Fields["PreviousYearSnapshotList"];
                Sitecore.Data.Items.Item[] items = multiselectField.GetItems();

                if (items != null && items.Length > 0)
                {
                    var listofsnapshot = new List <PreviousYearSnapshotDetails>();
                    for (int i = 0; i < items.Length; i++)
                    {
                        Sitecore.Data.Items.Item snapshotItem = items[i];

                        Sitecore.Data.Fields.ImageField field = items[i].Fields["PreviousYearImage"];

                        var snapshotdetail = new PreviousYearSnapshotDetails()
                        {
                            PreviousYearTitle       = FieldRenderer.Render(snapshotItem, "PreviousYearTitle"),
                            PreviousYear            = FieldRenderer.Render(snapshotItem, "PreviousYear"),
                            PreviousYearDescription = FieldRenderer.Render(snapshotItem, "PreviousYearDescription"),
                            PreviousYearImage       = MediaManager.GetMediaUrl(field.MediaItem)
                        };
                        listofsnapshot.Add(snapshotdetail);
                    }
                    var returnviewmodel = new PastYearSnapshotViewModel()
                    {
                        PreviousYearSnapshotTitle = previousyearinformation,
                        PreviousYearSnapshotList  = listofsnapshot
                    };

                    return(View("~/Views/PreviousYear/PreviousYear.cshtml", returnviewmodel));
                }
                ;
            }
            return(View("~/Views/PreviousYear/PreviousYear.cshtml", null));
        }
        /// <summary>
        /// Judges Information Section
        /// </summary>
        /// <returns></returns>
        public ActionResult RenderJudgesInfoSection()
        {
            var currentItem  = RenderingContext.Current.Rendering.Item;
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var dataSource   = Sitecore.Context.Database.GetItem(dataSourceId);

            if (dataSource != null)
            {
                var judgeinformation = dataSource.Fields["JudgesInformation"]?.Value;
                Sitecore.Data.Fields.MultilistField multiselectField =
                    dataSource.Fields["JudgesList"];
                Sitecore.Data.Items.Item[] items = multiselectField.GetItems();

                if (items != null && items.Length > 0)
                {
                    var listofjudges = new List <JudgesDetails>();
                    for (int i = 0; i < items.Length; i++)
                    {
                        Sitecore.Data.Items.Item judgeItem = items[i];

                        Sitecore.Data.Fields.ImageField field = items[i].Fields["JudgesPic"];

                        var judgedetail = new JudgesDetails()
                        {
                            JudgesInfo       = FieldRenderer.Render(judgeItem, "JudgesInfo"),
                            JudgeName        = FieldRenderer.Render(judgeItem, "JudgeName"),
                            JudgesProfession = FieldRenderer.Render(judgeItem, "JudgesProfession"),
                            JudgesPic        = MediaManager.GetMediaUrl(field.MediaItem)
                        };
                        listofjudges.Add(judgedetail);
                    }
                    var returnviewmodel = new JudgesViewModel()
                    {
                        JudgesList        = listofjudges,
                        JudgesInformation = judgeinformation
                    };

                    return(View("~/Views/JudgesInformation/JudgesInformation.cshtml", returnviewmodel));
                }
                ;
            }
            return(View("~/Views/JudgesInformation/JudgesInformation.cshtml", null));
        }
Exemple #7
0
        /// <summary>
        /// Gets a List of items from a multilistfield list suitable for populating a repeater.
        /// </summary>
        /// <param name="item">Item which has the multilist</param>
        /// <param name="MaxToReturn"/>max or -1 for all;</param>
        /// <param name="fieldName">The fieldname of the multilistlist field</param>
        /// <returns>A List of Sitecore.DataItems.Item</returns>
        public static List <Sitecore.Data.Items.Item> GetItemsFromMultilist(Sitecore.Data.Items.Item item, string fieldName, int MaxToReturn)
        {
            List <Sitecore.Data.Items.Item> items = new List <Item>();

            if (null != item)
            {
                Sitecore.Data.Fields.MultilistField mulitlistField = item.Fields[fieldName];
                if (null != mulitlistField && null != mulitlistField.Items && mulitlistField.Items.Length > 0)
                {
                    items       = mulitlistField.GetItems().ToList <Sitecore.Data.Items.Item>();
                    MaxToReturn = (MaxToReturn == -1 ? items.Count : MaxToReturn);
                    if (items.Count > MaxToReturn)
                    {
                        for (int i = items.Count - 1; i > MaxToReturn; i--)
                        {
                            items.RemoveAt(i);
                        }
                    }
                }
            }
            return(items);
        }
Exemple #8
0
        /// <summary>
        /// Render Journey controller
        /// </summary>
        /// <returns></returns>
        public ActionResult RenderJourneySection()
        {
            //var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var dataSource = Sitecore.Context.Database.GetItem(RenderingContext.CurrentOrNull.Rendering.DataSource);

            if (dataSource != null)
            {
                Sitecore.Data.Fields.MultilistField multiselectField =
                    dataSource.Fields["HackathonJourney"];
                Sitecore.Data.Items.Item[] items = multiselectField.GetItems();

                if (items != null && items.Length > 0)
                {
                    var listofjourneydetails = new List <JourneyDetails>();

                    for (int i = 0; i < items.Length; i++)
                    {
                        Sitecore.Data.Items.Item journeyItem = items[i];
                        var journeydetail = new JourneyDetails()
                        {
                            JourneyHeader  = FieldRenderer.Render(journeyItem, "JourneyHeader"),
                            JourneyCaption = FieldRenderer.Render(journeyItem, "JourneyCaption"),
                            JourneyStyle   = FieldRenderer.Render(journeyItem, "JourneyStyle")
                        };
                        listofjourneydetails.Add(journeydetail);
                    }
                    var returnviewmodel = new JourneyViewModel()
                    {
                        JourneyListDetails = listofjourneydetails
                    };
                    return(View("~/Views/Journey/Journey.cshtml", returnviewmodel));
                }
            }
            return(View("~/Views/Journey/Journey.cshtml", null));

            // var currentItem = SitecoreContext.GetCurrentItem<IGlassBase>();
            //var contentdata = _contentLogic.GetBanner();
            // return View(_contentLogic.GetBanner());
        }
  /// <summary>
 /// If they are not children of the item in DataSourceField, remove GUIDs from a list of selected values
  /// </summary>
  private string SanitizeValues(Item sourceItem, Item parentItem, Item[] labelItems, string value)
  {
      var db = GetDatabase();
      if (value == null || String.IsNullOrEmpty(value.Trim())) return String.Empty;
      var ids = value.Split('|');
      var validItems = new List<Item>();
      Sitecore.Data.Fields.MultilistField components = null;
      for (int i = 0; i < ids.Length; i++)
      {
          var item = db.GetItem(new ID(ids[i]), Language.Parse(ItemLanguage));
          if (item != null && item.Axes.IsDescendantOf(sourceItem))
          {
              foreach (Item labelItem in labelItems)
              {
                  components = (Sitecore.Data.Fields.MultilistField)labelItem.Fields["ComponentName"];
                  if (components != null && labelItem != null && item != null && labelItem.ID.ToString() == item.ID.ToString() && components.List != null && parentItem != null && parentItem.Fields["Content Type"] != null && !string.IsNullOrEmpty(parentItem.Fields["Content Type"].Value) && components.List.ToString().Contains(parentItem.Fields["Content Type"].Value))
                  {
                      validItems.Add(item);
                  }
              }
          }
      }
      return String.Join("|", validItems.ConvertAll((x) => x.ID.ToString()));
  }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            if (Comment.Text == PreviousComment.Text)
            {
                AreYouSure.Visible       = true;
                ReviewCommentBox.Visible = true;
                return;
            }
            AreYouSure.Visible = false;

            var comment = Comment.Text;

            var dataSource = GetDataSourceItem();

            List <Word> words = new List <Word>();

            Sitecore.Data.Fields.MultilistField flaggedWords = dataSource.Fields["Flagged Words"];
            Sitecore.Data.Fields.MultilistField wordGroups   = dataSource.Fields["Flagged Word Groups"];

            var cooldownTime = dataSource.Fields["Cooldown Minutes"].Value;

            foreach (var wordItem in flaggedWords.GetItems())
            {
                words.AddRange(GetWords(wordItem));
            }

            foreach (var wordGroup in wordGroups.GetItems())
            {
                var warning = wordGroup.Fields["Warning Text"].Value;
                Sitecore.Data.Fields.MultilistField wordsField = wordGroup.Fields["Words"];
                foreach (var wordItem in wordsField.GetItems())
                {
                    words.AddRange(GetWords(wordItem, warning));
                }
            }

            var warnings = 0;

            foreach (var word in words) // scan comment for the word
            {
                warnings += comment.CountMatches(word.Value);

                var regex = new Regex(word.Value, RegexOptions.IgnoreCase);

                string formattedWord = String.Format("<span class='warning-word' style='background-color:{2}'>{0}<span class='tool-tip'>{1}</span></span>", word.Value, word.Warning, word.Color);

                comment = regex.Replace(comment, formattedWord);
            }

            ReviewCommentText.Text = comment;

            if (warnings > 0)
            {
                PreviousComment.Text = Comment.Text;
                //TotalWarnings.Text = (warnings + Int32.Parse(TotalWarnings.Text)).ToString();
                ReviewCommentBox.Visible = true;
            }
            else
            {
                SubmitComment();
            }
        }
Exemple #11
0
        // GET: Default
        public ActionResult SubmitComment(CivilCommentsSectionViewModel model)
        {
            model.ClearTextbox = false;
            if (model.SubmitShittyComment == "true")
            {
                CreateComment(model);
                return(View("/Views/CivilCommentsSection.cshtml", new CivilCommentsSectionViewModel()
                {
                    ClearTextbox = true
                }));
            }

            model.PromptAreYouSure = false;

            var comment    = model.Comment;
            var dataSource = model.DatasourceItem;

            List <Word> words = new List <Word>();

            Sitecore.Data.Fields.MultilistField flaggedWords = dataSource.Fields["Flagged Words"];
            Sitecore.Data.Fields.MultilistField wordGroups   = dataSource.Fields["Flagged Word Groups"];

            var cooldownTime = dataSource.Fields["Cooldown"].Value;

            int cooldown = 5000;

            if (!String.IsNullOrEmpty(cooldownTime))
            {
                if (int.TryParse(cooldownTime, out cooldown))
                {
                    model.Cooldown = cooldown;
                }
            }

            foreach (var wordItem in flaggedWords.GetItems())
            {
                words.AddRange(GetWords(wordItem));
            }

            foreach (var wordGroup in wordGroups.GetItems())
            {
                var warning = wordGroup.Fields["Warning Text"].Value;
                Sitecore.Data.Fields.MultilistField wordsField = wordGroup.Fields["Words"];
                foreach (var wordItem in wordsField.GetItems())
                {
                    words.AddRange(GetWords(wordItem, warning));
                }
            }

            var warnings = 0;

            foreach (var word in words) // scan comment for the word
            {
                warnings += comment.CountMatches(word.Value);

                var regex = new Regex(word.Value, RegexOptions.IgnoreCase);

                string formattedWord = String.Format("<span class='warning-word' style='background-color:{2}'>{0}<span class='tool-tip'>{1}</span></span>", word.Value, word.Warning, word.Color);

                comment = regex.Replace(comment, formattedWord);
            }

            model.ReviewText = comment;

            if (model.Comment == model.PreviousComment)
            {
                model.PromptAreYouSure = true;
                model.DisplayWarnings  = true;
                model.PreviousComment  = model.Comment;
                return(View("/Views/CivilCommentsSection.cshtml", model));
            }

            if (warnings > 0)
            {
                model.DisplayWarnings = true;
                model.PreviousComment = model.Comment;
                model.TotalWarnings  += warnings;
                return(View("/Views/CivilCommentsSection.cshtml", model));
            }
            else
            {
                CreateComment(model);
                return(View("/Views/CivilCommentsSection.cshtml", new CivilCommentsSectionViewModel()
                {
                    ClearTextbox = true
                }));
            }
        }
Exemple #12
0
        public IEnumerable <Data.Items.Item> filterSPG(IEnumerable <Data.Items.Item> items, string _penawaran, string _category, string _keyword, string id)
        {
            if (_penawaran.ToLower() == id.ToLower())
            {
                _penawaran = string.Empty;
            }

            Sitecore.Data.Items.Item dataSourceItem = Sitecore.Context.Database.GetItem(new Data.ID(id));
            if (String.IsNullOrEmpty(_penawaran))
            {
                Sitecore.Data.Items.Item ItemCountryPromotion = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.CountryPromotion.ID).FirstOrDefault();
                if (ItemCountryPromotion != null)
                {
                    Sitecore.Data.Fields.MultilistField SelectedCountryPromotion = ItemCountryPromotion.Fields[Sitecore.Feature.Library.Templates.CountryPromotion.Fields.Location];
                    if (SelectedCountryPromotion.GetItems().Count() > 0)
                    {
                        //Sitecore.Data.Items.Item defaultSelectedCountry = SelectedCountryPromotion.GetItems().FirstOrDefault();
                        //items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(defaultSelectedCountry.ID.ToString().ToLower()));
                        items = items.Where(x => SelectedCountryPromotion.GetItems().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(y.ID.ToString().ToLower())));
                    }
                }
            }
            else
            {
                items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(_penawaran.ToLower()));
            }

            if (string.IsNullOrEmpty(_category))
            {
                Sitecore.Data.Items.Item            ItemProductCategory     = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.ListCategoryPromotion.ID).FirstOrDefault();
                Sitecore.Data.Fields.MultilistField SelectedProductCategory = ItemProductCategory.Fields[Sitecore.Feature.Library.Templates.ListCategoryPromotion.Fields.Category];
                if (SelectedProductCategory.GetItems().Count() > 0)
                {
                    string[] idCategories = SelectedProductCategory.GetItems().Select(x => x.ID.ToString().ToLower()).ToArray();
                    items = items.Where(x => idCategories.Where(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(y.ToLower())).Any());
                }
            }
            else
            {
                items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(_category.ToLower()));
            }

            if (!String.IsNullOrEmpty(_keyword))
            {
                List <Data.Items.Item> oList = new List <Data.Items.Item>();

                foreach (Data.Items.Item ItemCountryPromotion in items)
                {
                    Sitecore.Data.Fields.MultilistField SelectedCountryPromotion = ItemCountryPromotion.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation];
                    foreach (Sitecore.Data.Items.Item SelectedItemContryPromotion in SelectedCountryPromotion.GetItems())
                    {
                        if (SelectedItemContryPromotion.DisplayName.ToLower() == _keyword.ToLower())
                        {
                            oList.Add(ItemCountryPromotion);
                        }
                    }
                }
                items = oList.AsEnumerable <Data.Items.Item>();
            }

            items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.Layout].Value.ToLower().Contains(dataSourceItem.ID.ToString().ToLower()));

            return(items);
        }
Exemple #13
0
        public IEnumerable <Data.Items.Item> filterItem360(IEnumerable <Data.Items.Item> items, string _penawaran, string _category, string _keyword, Sitecore.Data.Items.Item dataSourceItem)
        {
            if (_penawaran.ToLower() == dataSourceItem.ID.ToString().ToLower())
            {
                _penawaran = string.Empty;
            }

            if (string.IsNullOrEmpty(_penawaran) && String.IsNullOrEmpty(_category))
            {
                IEnumerable <Sitecore.Data.Items.Item> ItemProductsPromotion = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.CategoryPromotion.ID);

                List <string> listIValueItemCategory = new List <string>();
                List <string> listProductPromotionID = new List <string>();
                foreach (Sitecore.Data.Items.Item selectItemProductPromotion in ItemProductsPromotion)
                {
                    string idItemCategory = selectItemProductPromotion.Fields[Sitecore.Feature.Library.Templates.CategoryPromotion.Fields.Category].Value;
                    Sitecore.Data.Items.Item iValueItemCategory = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(idItemCategory));
                    listIValueItemCategory.Add(iValueItemCategory.ID.ToString().ToLower());

                    foreach (Sitecore.Data.Items.Item productPromotionList in selectItemProductPromotion.Children.Where(x => x.TemplateID == Sitecore.Feature.Library.Templates.ProductPromotion.ID))
                    {
                        Sitecore.Data.Fields.MultilistField getProductPromotionList = productPromotionList.Fields[Sitecore.Feature.Library.Templates.ProductPromotion.Fields.Product];
                        foreach (string productPromotionID in getProductPromotionList.GetItems().Select(x => x.ID.ToString().ToLower()))
                        {
                            listProductPromotionID.Add(productPromotionID);
                        }
                    }
                }

                if (listIValueItemCategory.Count > 0)
                {
                    items = items.Where(x => listIValueItemCategory.Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(y)));
                }

                if (listProductPromotionID.Distinct().Count() > 0)
                {
                    items = items.Where(x => listProductPromotionID.Distinct().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductItem].Value.ToLower().Contains(y)));
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(_penawaran))
                {
                    Data.Items.Item          ItemPenawaran      = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(_penawaran));
                    string                   idItemCategory     = ItemPenawaran.Fields[Sitecore.Feature.Library.Templates.CategoryPromotion.Fields.Category].Value;
                    Sitecore.Data.Items.Item iValueItemCategory = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(idItemCategory));
                    items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.Contains(iValueItemCategory.ID.ToString()));
                }

                if (!String.IsNullOrEmpty(_category))
                {
                    Data.Items.Item ItemCategory = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(_category));
                    items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductItem].Value.Contains(ItemCategory.ID.ToString()));
                }
                else
                {
                    Data.Items.Item ItemPenawaran = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(_penawaran));
                    if (ItemPenawaran.Children.Where(x => x.TemplateID == Sitecore.Feature.Library.Templates.ProductPromotion.ID).Count() > 0)
                    {
                        Sitecore.Data.Items.Item CategoryItem = ItemPenawaran.Children.Where(x => x.TemplateID == Sitecore.Feature.Library.Templates.ProductPromotion.ID).FirstOrDefault();
                        if (CategoryItem != null)
                        {
                            Sitecore.Data.Fields.MultilistField SelectedProductCategory = CategoryItem.Fields[Sitecore.Feature.Library.Templates.ProductPromotion.Fields.Product];
                            if (SelectedProductCategory.GetItems().Count() > 0)
                            {
                                string[] idCategories = SelectedProductCategory.GetItems().Select(x => x.ID.ToString().ToLower()).ToArray();
                                items = items.Where(x => idCategories.Where(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductItem].Value.ToLower().Contains(y.ToLower())).Any());
                            }
                        }
                    }
                }

                if (!String.IsNullOrEmpty(_keyword))
                {
                    //IEnumerable<Data.Items.Item> locItem = new Data.Items.Item[] { };
                    List <Data.Items.Item> oList = new List <Data.Items.Item>();

                    //items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToLower().Contains(_keyword.ToLower()));
                    foreach (Data.Items.Item loc in items)
                    {
                        string locIds = loc.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value;

                        foreach (string locId in locIds.Split('|'))
                        {
                            try {
                                Data.Items.Item locItem = Sitecore.Context.Database.GetItem(new Data.ID(locId));
                                if (locItem.DisplayName.ToLower() == _keyword.ToLower())
                                {
                                    oList.Add(loc);
                                }
                            } catch (Exception) { }
                        }
                    }

                    items = oList.AsEnumerable <Data.Items.Item>();
                }
            }

            items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.Layout].Value.ToLower().Contains(dataSourceItem.ID.ToString().ToLower()));

            return(items);
        }
Exemple #14
0
        public IEnumerable <Data.Items.Item> filterItemBeautifulIndonesia(IEnumerable <Data.Items.Item> items, string _city, string _category, string id)
        {
            if (_city == id.ToLower())
            {
                _city = string.Empty;
            }

            Sitecore.Data.Items.Item dataSourceItem = Sitecore.Context.Database.GetItem(new Data.ID(id));
            //Sitecore.Data.Items.Item dataSourceItem = RenderingContext.Current.Rendering.Item;

            if (String.IsNullOrEmpty(_city) && String.IsNullOrEmpty(_category))
            {
                Sitecore.Data.Items.Item ItemLocationPromotion = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.LocationPromotion.ID).FirstOrDefault();
                if (ItemLocationPromotion != null)
                {
                    Sitecore.Data.Fields.MultilistField oItemLocationPromotion = ItemLocationPromotion.Fields[Sitecore.Feature.Library.Templates.LocationPromotion.Fields.Location];
                    if (oItemLocationPromotion.GetItems().Count() > 0)
                    {
                        //Sitecore.Data.Items.Item defaultLocation = oItemLocationPromotion.GetItems()[0];
                        Sitecore.Data.Items.Item ItemProductCategory = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.ListCategoryPromotion.ID).FirstOrDefault();
                        if (ItemProductCategory != null)
                        {
                            Sitecore.Data.Fields.MultilistField oItemProductCategory = ItemProductCategory.Fields[Sitecore.Feature.Library.Templates.ListCategoryPromotion.Fields.Category];
                            if (oItemProductCategory.GetItems().Count() > 0)
                            {
                                string[] idCategories = oItemProductCategory.GetItems().Select(x => x.ID.ToString().ToLower()).ToArray();
                                items = items.Where(x => idCategories.Where(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(y.ToLower())).Any());
                                items = items.Where(x => oItemLocationPromotion.GetItems().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(y.ID.ToString().ToLower())));
                            }
                        }
                        else
                        {
                            //items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(defaultLocation.ID.ToString().ToLower()));
                            items = items.Where(x => oItemLocationPromotion.GetItems().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(y.ID.ToString().ToLower())));
                        }
                    }
                }
            }
            else if (String.IsNullOrEmpty(_city))
            {
                Sitecore.Data.Items.Item ItemLocationPromotion = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.LocationPromotion.ID).FirstOrDefault();
                if (ItemLocationPromotion != null)
                {
                    Sitecore.Data.Fields.MultilistField oItemLocationPromotion = ItemLocationPromotion.Fields[Sitecore.Feature.Library.Templates.LocationPromotion.Fields.Location];
                    if (oItemLocationPromotion.GetItems().Count() > 0)
                    {
                        //Sitecore.Data.Items.Item defaultLocation = oItemLocationPromotion.GetItems()[0];
                        if (!String.IsNullOrEmpty(_category))
                        {
                            items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(_category.ToLower()));
                            items = items.Where(x => oItemLocationPromotion.GetItems().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(y.ID.ToString().ToLower())));
                        }
                        else
                        {
                            //items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(defaultLocation.ID.ToString().ToLower()));
                            items = items.Where(x => oItemLocationPromotion.GetItems().Any(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(y.ID.ToString().ToLower())));
                        }
                    }
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(_city))
                {
                    items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductLocation].Value.ToString().ToLower().Contains(_city.ToLower()));
                }

                if (!String.IsNullOrEmpty(_category))
                {
                    items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(_category.ToLower()));
                }
                else
                {
                    Sitecore.Data.Items.Item ItemProductCategory = dataSourceItem.Children.Where(x => x.Template.ID == Sitecore.Feature.Library.Templates.ListCategoryPromotion.ID).FirstOrDefault();
                    if (ItemProductCategory != null)
                    {
                        Sitecore.Data.Fields.MultilistField oItemProductCategory = ItemProductCategory.Fields[Sitecore.Feature.Library.Templates.ListCategoryPromotion.Fields.Category];
                        if (oItemProductCategory.GetItems().Count() > 0)
                        {
                            string[] idCategories = oItemProductCategory.GetItems().Select(x => x.ID.ToString().ToLower()).ToArray();
                            items = items.Where(x => idCategories.Where(y => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.ProductCategory].Value.ToLower().Contains(y.ToLower())).Any());
                        }
                    }
                }
            }

            items = items.Where(x => x.Fields[Sitecore.Feature.Library.Templates.PromotionPageCreditCard.Fields.Layout].Value.ToLower().Contains(dataSourceItem.ID.ToString().ToLower()));

            return(items);
        }