/// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Load(object sender, EventArgs e)
        {
            Item context = Sitecore.Context.Item;

            if (context.TemplateID == TemplateReferences.Holiday)
            {
                PageHeading.Item = context.Axes.GetDescendants().Where(x => x.TemplateID == TemplateReferences.HolidayDates).FirstOrDefault();

                /* 'GetDescendants' is an expensive operation if you do it on a large tree - make sure you know the section
                 * of the tree you are targeting is never going to grow beyond a certain size. In this case, we know holiday
                 * dates will be limited to ~ 20. For more common mistakes, see: http://blog.boro2g.co.uk/common-mistakes-when-programming-with-sitecore-pt1/.
                 */

                List <Item> descendants = Sitecore.Context.Item.Axes.GetDescendants().ToList();

                if (descendants.Any())
                {
                    List <Item> holidayDates = descendants.Where(x => x.TemplateID == TemplateReferences.HolidayDate).ToList();

                    if (holidayDates.Any())
                    {
                        holidayDates.OrderByDescending(x => HolidayUtils.GetHolidayDateRange(x).StartDate);

                        rpDays.DataSource = holidayDates.Where(x => HolidayUtils.GetHolidayDateRange(x).StartDate > DateTime.Today);
                        rpDays.DataBind();
                    }

                    SummaryHeading.Item = context;

                    txtType.Item       = FieldUtils.GetReferenceFieldItem(fnType);
                    txtDifficulty.Item = FieldUtils.GetReferenceFieldItem(fnDifficulty);

                    List <Item> terrains = FieldUtils.GetListFieldItems(fnTerrain);

                    if (terrains.Any())
                    {
                        litTerrain.Text = string.Join(", ", terrains.Select(x => FieldUtils.GetFieldValue(x, Keys.SimpleTextFieldName)));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Page_Load(object sender, EventArgs e)
        {
            Item source = GetItem();

            if (source.TemplateID == TemplateReferences.Holiday)
            {
                PageHeading.Item = source.Axes.GetDescendants().Where(x => x.TemplateID == TemplateReferences.HolidayDates).FirstOrDefault();

                /* 'GetDescendants' is an expensive operation if you do it on a large tree - make sure you know the section
                 * of the tree you are targeting is never going to grow beyond a certain size. In this case, we know holiday
                 * dates will be limited to ~ 20. For more common mistakes, see: http://blog.boro2g.co.uk/common-mistakes-when-programming-with-sitecore-pt1/.
                 */

                List <Item> descendants = Sitecore.Context.Item.Axes.GetDescendants().ToList();

                if (descendants.Any())
                {
                    /* 'HolidayDate' is a so-called 'custom item'. Navigate to the class to find out more about the
                     * custom item pattern in Sitecore.
                     */

                    /* TODO: Refactor to use search instead */

                    List <Item> holidayDates = descendants.Where(x => x.TemplateID == TemplateReferences.HolidayDate && x.Versions.Count > 0).ToList();

                    var validDates = holidayDates.Where(x => HolidayUtils.GetHolidayDateRange(x).StartDate > DateTime.Today);

                    if (validDates.Any())
                    {
                        rpDays.DataSource = validDates;
                        rpDays.DataBind();
                    }
                    else
                    {
                        NoHolidays.Visible = true;
                    }
                }
            }
        }