コード例 #1
0
        private List <RadioEpisode> GetNeighbourEpisodes(RadioEpisode currentEpisode, List <RadioEpisode> allRadioEpisodes)
        {
            if (currentEpisode == null || allRadioEpisodes == null || !allRadioEpisodes.Any())
            {
                return(null);
            }
            //get 3 most recent previous episodes and 3 next episodes excluding the current episode
            const int episodesToShow      = 7; //includes current episode removed later
            var       currentEpisodeIndex = allRadioEpisodes.FindIndex(e => currentEpisode != null && e.Id == currentEpisode.Id);
            var       startIndex          = Math.Max(currentEpisodeIndex - 3, 0);
            var       lastIndex           = Math.Min(currentEpisodeIndex + 3, allRadioEpisodes.Count - 1);

            startIndex = Math.Min(startIndex, lastIndex - episodesToShow + 1);

            var neighbourEpisodes = allRadioEpisodes.Skip(startIndex).Take(lastIndex - startIndex + 1).ToList();

            currentEpisodeIndex = neighbourEpisodes.FindIndex(e => currentEpisode != null && e.Id == currentEpisode.Id);
            if (currentEpisodeIndex >= 0)
            {
                neighbourEpisodes.RemoveAt(currentEpisodeIndex);
            }

            neighbourEpisodes.Reverse();

            return(neighbourEpisodes);
        }
コード例 #2
0
        private Item GetCurrentEpisodeItem(Item currentItem, RadioEpisode currentEpisode)
        {
            if (currentItem.TemplateName == "Radio Episode")
            {
                return(currentItem);
            }

            return(currentEpisode == null ? null : Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(currentEpisode.Id)));
        }
        private void BuildEpisodeListOfMonth(Item contextItem)
        {
            if (contextItem.TemplateName != "Radio Folder Month")
            {
                return;
            }

            var episodeList = new List <RadioEpisode>();

            foreach (var c in contextItem.Children.ToList())
            {
                var radioEpisode = new RadioEpisode();
                radioEpisode.Title           = c.Fields["Radio Episode Title"].GetValue(true);
                radioEpisode.RadioEpisodeUrl = Sitecore.Links.LinkManager.GetItemUrl(c);
                var radioEpisodeDateField = c.Fields["Radio Episode Date"];
                if (radioEpisodeDateField != null && ((Sitecore.Data.Fields.DateField)radioEpisodeDateField) != null)
                {
                    radioEpisode.Date = ((Sitecore.Data.Fields.DateField)radioEpisodeDateField).DateTime;
                }
                episodeList.Add(radioEpisode);
            }
            _relom = episodeList.OrderByDescending(c => c.Date).ToList();
        }
コード例 #4
0
 public RadioPageViewModel()
 {
     NeighbourEpisodes = new List <RadioEpisode>();
     CurrentEpisode    = new RadioEpisode();
 }