Populating RadCalander Special Days from Sitefinity Events

Posted by Community Admin on 04-Aug-2018 21:49

Populating RadCalander Special Days from Sitefinity Events

All Replies

Posted by Community Admin on 13-May-2013 00:00

Hello Friends,

I have been working with Sitefinity for a little over a year, and it has spurred my quest of taking my HTML skills to the next level and moving from Web Designer to Web Developer.

So I have a book on ASP.NET and have been going though it and have become somewhat comfortable working with code behind and all that jazz. 

Currently I have created a custom widget (control) and registered it with sitefinity. My widget houses a telerik RadCalander.

Is what I would like to accomplish is to be able to create events in the Sitefinity backend, tag those events with specific categories and have the dates that show up as Special Days on my RadCalander with a specific color border based on the category. Then when you hover over that specific date the body of that even is the ToolTip of the special day.

Any pointers, hints or steps in the right direction would be greatly appreciated. 

-Tyler

Posted by Community Admin on 13-May-2013 00:00

Well, I kind of figured it out. This is my following code : 

var eventitems = App.WorkWith().Events().Get().ToList();
            
           foreach (Event element in eventitems)
           
               DateTime d = element.EventStart;
               Telerik.Web.UI.RadCalendarDay day = new Telerik.Web.UI.RadCalendarDay();
               string eventInformation = element.Content;
               day.Date = d;
               day.ToolTip = eventInformation;
               day.ItemStyle.CssClass = "TestClass";
               homeCalander.SpecialDays.Add(day);
           

The next step is to filter them by category, and based on category give each item a ItemStyle. I have tried useing the taxonomy manager before, with little success.

If someone could post an example of my code that filters for the category 'Closed Date' that would be huge!

Thanks,

-Tyler

Posted by Community Admin on 16-May-2013 00:00

Hello,

You can filter events and other content items by category by getting the value of the category field with the GetValue extension method. Here is an example for news items. The approach with events is the same:

NewsManager newsManager = NewsManager.GetManager();
   
            var news = newsManager.GetNewsItems().Where(newsItem => newsItem.Status == ContentLifecycleStatus.Live).ToList();
   
            var tMan =Telerik.Sitefinity.Taxonomies.TaxonomyManager.GetManager();
            var myCat = tMan.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == "myCategory").SingleOrDefault().Id;
            var myList = new List<Telerik.Sitefinity.News.Model.NewsItem>();
               
            for (var i = 0; i < news.Count; i++)
            
                var category = news[i].GetValue<TrackedList<Guid>>("Category");
                if (category.Contains(myCat))
                
                    myList.Add(news[i]);
                
                   
            

I would also suggest you to review this forum thread:

http://www.sitefinity.com/developer-network/forums/general-discussions-/filter-events-by-category


Regards,
Stefani Tacheva
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 16-May-2013 00:00

Eureka!

You know, I've been so close. I actually saw that post probably 20 times, but whenever I was trying to use the GetValue() method it was showing up red. Typically I can highlight it and VisualStudio will add the reference for me. 

I was simply missing the Using Telerik.Sitefinity.Model;

Such a rookie mistake. :\

Here is my code if anyone is interested:

//Get the ID from the GetCategoryByTitle() Method
           var catID = GetCategoryByTitle("Calender - Close Date");
           Guid id1 = catID.Id;
 
           //Get a list of all the events with the category ID found above
           var eventitems = App.WorkWith().Events().Get()
                                                       .Where(t => t.Status == ContentLifecycleStatus.Live)
                                                       .Where(t => t.GetValue<TrackedList<Guid>>("Category").Contains(id1))
                                                       .ToList();
            
           //Loop through events and add them to the Calander
           foreach (Event element in eventitems)
           
               DateTime d = element.EventStart;
               Telerik.Web.UI.RadCalendarDay day = new Telerik.Web.UI.RadCalendarDay();
               string eventInformation = element.Content;
               day.Date = d;
               day.ToolTip = eventInformation;
               day.ItemStyle.CssClass = "Closed";
               day.IsSelectable = false;
               homeCalander.SpecialDays.Add(day);
           

in the above code I am calling the following method to retrieve Guids that I have pulled from these forums:

public Taxon GetCategoryByTitle(string title)
        
            var taxonomyMgr = TaxonomyManager.GetManager();
 
            HierarchicalTaxonomy category = taxonomyMgr.GetTaxonomies<HierarchicalTaxonomy>().Where(x => x.Name == "Categories").SingleOrDefault();
 
            if (category == null)
            
                return null;
            
 
            return category.Taxa.Where(x => x.Title == title).SingleOrDefault();
        

Thank you very much!

-Tyler

Posted by Community Admin on 17-May-2013 00:00

Hi,

I am glad to hear that you have managed to filter the events by category using the information and sample I have sent you. Thank you for sharing your solution with the community.

All the best,
Stefani Tacheva
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed