Events Calender Help...

Posted by Community Admin on 03-Aug-2018 22:56

Events Calender Help...

All Replies

Posted by Community Admin on 28-Jan-2011 00:00

I am working with the new Sitefinity 4.0 for the first time and all is going well. Part of the project is an events calendar and I am having trouble connecting my Events I create to a RadControl Calendar. Are there any blogs, examples, or discussions on the subject in 4.0 before I go getting into the code? It kind of seemed like the two controls would play nice together in a strait forward way.

I would like a calendar on the left with the events to show up and perhaps a detailed description of the events on the right using the Events control.

Thanks for any help,

Charles

Posted by Community Admin on 29-Jan-2011 00:00

The Intranet Starter Kit has events module....

Have a look at it... It might give you some clues...

Posted by Community Admin on 11-Feb-2011 00:00

Hey Charles,

I'm trying to perform a similar task with the Calendar in Sitefinity 4.0. Have you had any luck getting the calendar to interact with the events?

Thanks,

Jeff

Posted by Community Admin on 11-Feb-2011 00:00

Not really...
I just formated the Event to look like a calender entry... I was looking for a little more detail to my question but did not get it so I just did what I could because I just don't have time right now to research it.. When I get this project done I will go back and search around... If I find something I will post it...
Charles

Posted by Community Admin on 11-Feb-2011 00:00

Hey Charles,

Would you mind posting a link to the calendar that you are using?

Thanks,

Jeff

Posted by Community Admin on 11-Feb-2011 00:00

Not using a calendart yet... i just formated the event widget to look like a calendar entry. I will go back later and hook in the calendar if I figure it out. <see pic>
Charles

Posted by Community Admin on 14-Feb-2011 00:00

Hi charles and Jeffrey,

That is a tough one. What I could suggest you is to use the RadScheduler for ASP.NET in a Month View mode and link it to the Events.

Please see the code samples below for further reference in building your EventsCalendar widget as a user control.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EventsCalendar.ascx.cs" Inherits="SitefinityWebApp.MyControls.EventsCalendar" %>
<telerik:RadScheduler runat="server" ID="Scheduler1" SelectedView="MonthView">
</telerik:RadScheduler>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Telerik.Sitefinity.News.Model;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
 
namespace SitefinityWebApp.MyControls
    public partial class EventsCalendar : System.Web.UI.UserControl
    
        protected void Page_Load(object sender, EventArgs e)
        
            var events = App.WorkWith().Events().Where(n => n.Status == ContentLifecycleStatus.Live).Get().ToList();
            Telerik.Sitefinity.Events.Model.Event ev;
            Scheduler1.DataSource = events;
            Scheduler1.DataKeyField = "Id";
            Scheduler1.DataSubjectField = "Title";
            Scheduler1.DataStartField="EventStart";
            Scheduler1.DataEndField="EventEnd";
            Scheduler1.DataBind();
        
    

I hope this information helps. Please let me know if I can assist you any further with this service request. Thank you in advance.

Greetings,
Boyan Barnev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 19-May-2011 00:00

Hi Boyan,

This code is perfect! It solved my problem. I am now trying to figure out how to tie it to a details page. Any ideas?

I'll post the full VB.net code for my control when I finish this little project.

Posted by Community Admin on 20-May-2011 00:00

Hi David Arnold,

Do you mind sharing with me some more details on the exact use case scenario you want to implement, so that I can give you a more focused answer. Thanks in advance.

Greetings,
Boyan Barnev
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 20-May-2011 00:00

Hi Boyan,

I submitted a ticket on this issue last night, but basically I have a few issues and one really bad work-around.

I have a radscheduler and it shows me one event (not all of the events?) from SiteFinity. I need to be able to link each event to the details page for that event. I think it's called EventView page in SiteFinity. I have listed my code at the bottom of this post.

My problems are:
1. Only one event shows up, not all of them
2. If an event start date changes, my link will break
3. Cannot go to another month (gives databinding error)

Here's my control:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CalendarView.ascx.vb" Inherits="Controls_CalendarView" %>
<telerik:RadScheduler runat="server" ID="Scheduler1" SelectedView="MonthView"
    AllowDelete="false"
    AllowEdit="false"
    AllowInsert="false"
    ShowViewTabs="false"
    OnClientNavigationCommand="OnClientNavigationCommand">
    <AppointmentTemplate>
        <asp:HyperLink ID="hyp1" runat="server" Text='<%# Eval("Subject") %>' NavigateUrl='<%# getURL(Eval("Start"), Eval("Subject"))%>' />
    </AppointmentTemplate>
</telerik:RadScheduler>
  
<script language="javascript">
    function OnClientNavigationCommand(sender, eventArgs)
        // 7 = SwitchToDayView  
        if (eventArgs.get_command() == 7) eventArgs.set_cancel(true);
      
  
</script>

And my code behind:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Telerik.Web.UI
Imports Telerik.Sitefinity.News.Model
Imports Telerik.Sitefinity
Imports Telerik.Sitefinity.GenericContent.Model
  
  
Partial Class Controls_CalendarView
    Inherits System.Web.UI.UserControl
  
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  
        Dim events = App.WorkWith().Events().Where(Function(n) n.Status = ContentLifecycleStatus.Live).[Get]().ToList()
  
        '--- was in example code, but not used anywhere?
        Dim ev As Telerik.Sitefinity.Events.Model.Event
  
        Scheduler1.DataSource = events
        Scheduler1.DataKeyField = "Id"
        Scheduler1.DataSubjectField = "Title"
        Scheduler1.DataStartField = "EventStart"
        Scheduler1.DataEndField = "EventEnd"
        Scheduler1.DataBind()
  
    End Sub
  
  
    Public Function getURL(eventDate As Date, title As String) As String  
        Dim _URL As String
        _URL = "/" & Year(eventDate)
        If Month(eventDate).ToString.Length = 1 Then
            _URL += "/0" & Month(eventDate)
        Else
            _URL += "/" & Month(eventDate)
        End If  
        If Day(eventDate).ToString.Length = 1 Then
            _URL += "/0" & Day(eventDate)
        Else
            _URL += "/" & Day(eventDate)
        End If
        _URL += "/" & LCase(Replace(title, " ", "-"))
        Return "~/calendar-view/event-details/" & _URL
    End Function
  
End Class

Thank you for your help.

Posted by Community Admin on 25-May-2011 00:00

Hi David Arnold,

Please check the provided code sample below, it should offer a solution to all of the listed problems.

First, enclosing the RadScheduler in a RadAjaxPanel and declaring the DataKeyField , DataSubjectField , DataStartField , and DataEndField properties in the template should fix the DataBind error you are receiving when you do a postback (for instance when switching to another date/view/month etc.)

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RadScheduler.ascx.cs" Inherits="SitefinityWebApp.Controls.RadScheduler" %>
<telerik:RadAjaxPanel runat="server">
<telerik:RadScheduler runat="server" ID="Scheduler1"
                        DataKeyField = "Id"
                        DataSubjectField = "Title"
                        DataStartField = "EventStart"
                        DataEndField = "EventEnd"
                        OnAppointmentCreated="Scheduler1_AppointmentCreated">
    <AppointmentTemplate>
        <asp:HyperLink id="eventDetailsLink" runat="server" />
    </AppointmentTemplate>
</telerik:RadScheduler>
</telerik:RadAjaxPanel>
and in the code-behind please inspect the way links to the event items are constructed - composing of the Event item default URL and a page which contains an Events widget, so that the event can be displayed there. You should set the property SinglePage from the widget settings in the UI, to a page which contains an Events widget  :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Events;
using Telerik.Sitefinity.Events.Model;
 
namespace SitefinityWebApp.Controls
    public partial class RadScheduler : System.Web.UI.UserControl
    
        protected void Page_Load(object sender, EventArgs e)
        
            Scheduler1.DataSource = GetSourceItems();               
        
 
        protected virtual IList<Event> GetSourceItems()
        
            var list = new List<Event>();
            list = App.WorkWith().Events().Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get().ToList();
            return list;
        
        public string SinglePage
        
            get;
            set;
 
        
 
 
        public void Scheduler1_AppointmentCreated(object sender, Telerik.Web.UI.AppointmentCreatedEventArgs e)
        
            var EManager = EventsManager.GetManager();
            var c = (HyperLink)e.Container.FindControl("eventDetailsLink");
            var data = EManager.GetEvent(new Guid(e.Appointment.ID.ToString()));
            c.Text = data.Title;
            c.NavigateUrl = SinglePage + data.Urls.Where(u => u.RedirectToDefault == false).SingleOrDefault().Url;
        
 
               
    
 
 
         
 
        
 
        
I hope you find this information useful, if you need any further assistance, please let us know.

Kind regards,
Boyan Barnev
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-Jun-2011 00:00

Hi Boyan,

Thanks so much for pointing me in the right direction! I had a few issues with your code. I converted it to VB.net and wanted to post my code for other users:

User control:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CalendarView.ascx.vb" Inherits="Controls_CalendarView" %>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
 
    <telerik:RadScheduler runat="server" ID="Scheduler1" SelectedView="MonthView"
        AllowDelete="false"
        AllowEdit="false"
        AllowInsert="false"
        ShowViewTabs="false"
        DataKeyField = "Id"
        DataSubjectField = "Title"
        DataStartField = "EventStart"
        DataEndField = "EventEnd"
        OnAppointmentCreated="Scheduler1_AppointmentCreated"
        OnClientNavigationCommand="OnClientNavigationCommand"
        >
        <AppointmentTemplate>
            <asp:HyperLink ID="eventDetailsLink" runat="server" />
        </AppointmentTemplate>
    </telerik:RadScheduler>
 
</telerik:RadAjaxPanel>
 
 
<script language="javascript">
    function OnClientNavigationCommand(sender, eventArgs)
        // 7 = SwitchToDayView 
        if (eventArgs.get_command() == 7) eventArgs.set_cancel(true);
     
 
</script>

Code behind:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Telerik.Sitefinity
Imports Telerik.Sitefinity.GenericContent.Model
Imports Telerik.Sitefinity.Modules.Events
Imports Telerik.Sitefinity.Events.Model
 
Partial Class Controls_CalendarView
    Inherits System.Web.UI.UserControl
 
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
 
        Scheduler1.DataSource = GetSourceItems()
 
    End Sub
 
 
    Protected Overridable Function GetSourceItems() As IList(Of [Event])
 
        Dim list = New List(Of [Event])()
        list = App.WorkWith().Events().Where(Function(c) c.Status = Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).[Get]().ToList()
        Return list
 
    End Function
 
    Public Property SinglePage() As String
        Get
            Return m_SinglePage
        End Get
        Set(value As String)
            m_SinglePage = Value
        End Set
    End Property
    Private m_SinglePage As String = "~/calendar-view/events-detail/"
 
    Public Sub Scheduler1_AppointmentCreated(sender As Object, e As Telerik.Web.UI.AppointmentCreatedEventArgs)
 
        Dim EManager = EventsManager.GetManager()
        Dim c = DirectCast(e.Container.FindControl("eventDetailsLink"), HyperLink)
        Dim data = EManager.GetEvent(New Guid(e.Appointment.ID.ToString()))
        c.Text = data.Title
        c.NavigateUrl = SinglePage + data.Urls.Where(Function(u) u.RedirectToDefault = False).FirstOrDefault().Url
 
    End Sub
End Class


Posted by Community Admin on 12-Aug-2011 00:00

What property will allow it to open in Month tab?
in otherwords, I want to see the Month view when I come to the page.

THanks

Posted by Community Admin on 12-Aug-2011 00:00

Hello Nana,

If you declare the SelectedView property to be equal to MonthView, this should ensure that RadScheduler will load initially in a month view mode. For more information on setting different view modes, please check this article from our documentation.

Greetings,
Boyan Barnev
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-Aug-2011 00:00

Thank you. I was able to implement sucessfully. Only that when I click on the event within the calender It goes to a url that is not within the cms.

am I supposed to enter anything in the single page property?

Posted by Community Admin on 18-Aug-2011 00:00

Hi Nana,

I have recorded a sample video demonstrating all the steps necessary for setting up the control on a Sitefinity project, please review them and let me know if any problems persist. Just a couple of things I'd like to stress on:
1. Make sure you are inserting the control in the proper folder, and then you are specifying the correct relative path to it
2. You'll need to substitute the .SingleOrDefault() filter in the lambda expression with .FirstOrDefault() to avoid exceptions when there are multiple Urls in the collection for that Event
3. You'll need to specify a value for the SinglePage property of the widget - it should be any page where you have dropped an Events widget, so when clicked from the Scheduler, the event can be properly opened.


Greetings,
Boyan Barnev
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 24-Aug-2011 00:00

Thanks Boyan
I understand your video perfectly.

My situation however is a bit different.

My events are categorized and are displayed on separate pages for each category (three) so in the SinglePage I cannot just put any page with an events control. The link has to go to the specific page and I have three event pages (categories.)


What else can I do?

Posted by Community Admin on 25-Aug-2011 00:00

Hi Nana,

In that case you can modify the code to get the category associated with the event item. You can get the category by using our extension method GetValue() (you will need to add a reference to Telerik.Sitefinity.Model;), for example:

var data = EventsManager.GetManager().GetEvent(new Guid());
            var category = data.GetValue("Category");
This will return a TrackedList of Guids of the categories assigned to the event, which you can loop through and get each category with TaxonomyManager. Once you have gotten the category, you can easily modify the code to redirect you to a specific page depending on the category.


Kind regards,
Boyan Barnev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Posted by Community Admin on 05-Oct-2011 00:00

Hi Boyen,
I have been having difficulty with this and need more assistance if you do not mind

I have
I have the event in a list

so this is what I have for

 

 

foreach (Event eventItem in list)

 


var data = EventsManager.GetManager().GetEvent(eventitem.id);
var category=data.getvalue("category")

now passing the value cateogory to the taxonomy manager is not working

I use
var taxon =taxManager.GetTaxon(category)
 I get type cast issues. please help further.

Thanks


Posted by Community Admin on 06-Oct-2011 00:00

Hello Nana,

You can store the Category Ids in a TrackedList of Guids like this:

var categoryIds =  evnt.GetValue<TrackedList<Guid>>("Categories");
and then browse through that list (since the relationship is one to many) like this:
foreach(var catId in categoryIds)
                
                    var category = TaxonomyManager.GetManager().GetTaxonomy(catId);
                
Alternatively, you can simply first get the category Id:
var myCategory1Id = TaxonomyManager.GetManager().GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "MyCategoryName").SingleOrDefault().Id;
 and then browse through these events that have this category assigned to them:
var allEvents = App.WorkWith().Events()
                                    .Where(t => t.Status == ContentLifecycleStatus.Live)                                  
                                    .Where(t => t.GetValue<TrackedList<Guid>>("Category").Contains( myCategory1Id )).Get().ToList();


All the best,
Boyan Barnev
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 10-Oct-2011 00:00

Hi, I am still not on the same page



 

 

 

 

 

var allEvents = App.WorkWith().Events()

 

.Where(t => t.Status == Telerik.Sitefinity.GenericContent.Model.

 

ContentLifecycleStatus.Live)

 

.Get()

.ToList();

 

 

foreach

 

 

(Event eventItem in allEvents)

 

 

 

var taxonManager = TaxonomyManager.GetManager();

 

 

 

var r = new TableRow();

 

 

 

var c = new TableCell();

 

 

 

 

var eventcat = eventItem.GetValue<Guid>("Category");

 

 

 

var catname = taxonManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Id == eventcat).SingleOrDefault();

 

 

c.Controls.Add(

 

new LiteralControl(eventItem.Title + catname.Name + " " + eventItem.EventStart + "-" + " " + eventItem.EventEnd + "<br />"));

 

r.Cells.Add(c);

Table1.Rows.Add(r);




My event is to category is 1 to 1
and I am thinking that the above code should work

but

var eventcat = eventItem.GetValue<Guid>("Category"); gives me a specified cast is not valid

 

so does

Guid eventcat = eventItem.GetValue<Guid>("Category");

 

 

 

 

Posted by Community Admin on 11-Oct-2011 00:00

Thank you. I kinda figured it out!

Posted by Community Admin on 11-Oct-2011 00:00

Hi Boyan,

I created a custom widget containing the RadScheduler. But I have this issue when inserting a new appoinment. I get the following javascript error when I hit save on insert new appoinment dialog. Any idea why? The type of data source of the scheduler is IList<Event>. Server side RadScheduler1_AppointmentInsert event is not getting called. but Update and Delete works fine without any issues.

Error:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid object passed in, member name expected. (46): "command":"InsertAppointment","appointment":,"Subject":"this%20test","Description":"","Resources":[],"RecurrenceState":0,"startDate":"201110111130","endDate":"201110111230"

Widget Template:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CalendarControl.ascx.cs"
    Inherits="SitefinityWebApp.CalendarControl" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
    TagPrefix="telerik" %>
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" Skin="Default" />
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
    <telerik:RadScheduler runat="server" ID="RadScheduler1" DataKeyField="Id" DataSubjectField="Title"
        DataStartField="EventStart" DataEndField="EventEnd" OnAppointmentCreated="RadScheduler1_AppointmentCreated"
        OnAppointmentDelete="RadScheduler1_AppointmentDelete" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate"
        OnAppointmentInsert="RadScheduler1_AppointmentInsert">
        <AppointmentTemplate>
            <div class="rsAptSubject">
                <%# Eval("Subject") %>
            </div>
            <asp:Label runat="server" ID="AssignedTo" />
        </AppointmentTemplate>
    </telerik:RadScheduler>
</telerik:RadAjaxPanel>


Thanks,
Duneel

Posted by Community Admin on 13-Oct-2011 00:00

Hi Duneel,

Can you please share with us how you're creating the appointment - do you subscribe to OnClientTimeSlotClick and open the Advanced edit form? If so, the showInsertFormAt() method should also fire the  corresponding FormCreating, AppointmentCreated and FormCreated server-side events. Maybe if you could fill us in with some more information on your exact implementation that would help us give you a more specific advice.

All the best,
Boyan Barnev
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 13-Oct-2011 00:00

Hi Duneel,

Just a quick follow-up, I believe I have managed to reproduce the issue at hand, can you please try wrapping your RadScheduler in RadAjaxPanel and let us know if the issue still persist?

All the best,
Boyan Barnev
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 13-Oct-2011 00:00

Hi Boyan,

RadSchedular is already wrapped inside RadAjaxPanel. Please have a look at the Widget Template I posted. Also I'm not using any client-side function. Everything is done in the server side events I have binded in RadSchedular (please check the widget template). All the other events fires but not the OnAppoinmentCreated, instead I get that javascript error.

Thanks!
Duneel

Posted by Community Admin on 18-Oct-2011 00:00

Any update on this please?

Thanks!
Duneel

Posted by Community Admin on 18-Oct-2011 00:00

Hi Duneel,

Thank you for the follow-up, would it be possible for you to send us the control so we can debug this problematic behavior? Thanks in advance.

Kind regards,
Boyan Barnev
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 18-Oct-2011 00:00

Sure. Here you go...

CalendarControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CalendarControl.ascx.cs"
    Inherits="SitefinityWebApp.CalendarControl" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
    TagPrefix="telerik" %>
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" Skin="Default" />
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
    <telerik:RadScheduler runat="server" ID="RadScheduler1" DataKeyField="Id" DataSubjectField="Title"
        DataStartField="EventStart" DataEndField="EventEnd" OnAppointmentCreated="RadScheduler1_AppointmentCreated"
        OnAppointmentDelete="RadScheduler1_AppointmentDelete" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate"
        OnAppointmentInsert="RadScheduler1_AppointmentInsert" SelectedView="WeekView">
        <AppointmentTemplate>
            <div class="rsAptSubject">
                <%# Eval("Subject") %>
            </div>
            <asp:Label runat="server" ID="AssignedTo" />
        </AppointmentTemplate>
    </telerik:RadScheduler>
</telerik:RadAjaxPanel>


CalendarControl.ascx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Events.Model;
using Telerik.Web.UI;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;
using Telerik.Sitefinity.Modules.Events;
 
namespace SitefinityWebApp
    public partial class CalendarControl : System.Web.UI.UserControl
    
        public string SinglePage
        
            get;
            set;
        
 
        protected void Page_Load(object sender, EventArgs e)
        
            GetLoggedInUser();
            RadScheduler1.DataSource = GetSourceItems();
        
 
        protected virtual IList<Event> GetSourceItems()
        
            var list = new List<Event>();
            list = App.WorkWith().Events().Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get().ToList();
            return list;
        
 
        protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
        
            Resource user = e.Appointment.Resources.GetResourceByType("User");
 
            if (user != null)
            
                Label assignedTo = (Label)e.Container.FindControl("AssignedTo");
                assignedTo.Text = "Booked By: " + user.Text;
            
 
            // Generate tooltip
            e.Appointment.ToolTip = GenerateTooltip(e.Appointment);
        
 
        protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e)
        
            // Delete appoinmnet
            if (e.Appointment != null)
            
                DeleteAppoinment(e.Appointment);
            
        
        protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
        
            // Update appoinment
            if (e.ModifiedAppointment != null)
            
                UpdateAppoinment(e.ModifiedAppointment);
                //CreateAppoinment(e.ModifiedAppointment);
            
        
        protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
        
            //if (e.Appointment.Resources.Count < 1)
            //    e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("Calendar", "1"));
 
            if (e.Appointment.Subject == String.Empty)
            
                e.Cancel = true;
            
        
 
        private User GetLoggedInUser()
        
            SitefinityPrincipal sp = SecurityManager.GetCurrentUser();
 
            User user = UserManager.FindUser(sp.UserId);
 
            return user;
        
 
        private void CreateAppoinment(Appointment appoinment)
        
            if (String.IsNullOrEmpty(appoinment.Subject))
                return;
 
            //Initialize the EventsManager with the default provider
            EventsManager manager = new EventsManager();
 
            //Create an Event
            Event eventItem = manager.CreateEvent();
 
            //Set the newly created event
            eventItem.Title = appoinment.Subject;
            eventItem.EventStart = appoinment.Start;
            eventItem.EventEnd = appoinment.End;
            eventItem.PublicationDate = DateTime.Today;
            eventItem.ExpirationDate = DateTime.Today.AddDays(365);
            eventItem.Content = appoinment.Subject;
 
            User user = GetLoggedInUser();
            if (user != null)
            
                eventItem.ContactName = user.FirstName + " " + user.LastName;
            
 
            //Generate an URL for the content item and Save the changes.
            manager.RecompileItemUrls<Event>(eventItem);
 
            //up to now, the item is in Draft State. We have to call Publish method to publish it.
            manager.Publish(eventItem);
            manager.SaveChanges();
 
            RadScheduler1.DataSource = GetSourceItems();
        
 
        private void UpdateAppoinment(Appointment appoinment)
        
            if (appoinment.Subject == null)
                return;
 
            EventsManager manager = EventsManager.GetManager();
            Event eventItem = manager.GetEvents()
                .Where(t => t.Id == (Guid)appoinment.ID)
                .FirstOrDefault();
 
            eventItem = manager.GetMaster(eventItem);
            Event temp = manager.CheckOut(eventItem);
 
            temp.Title = appoinment.Subject;
            temp.EventStart = appoinment.Start;
            temp.EventEnd = appoinment.End;
            temp.Content = appoinment.Subject;
 
            eventItem = manager.CheckIn(temp);
 
            manager.RecompileItemUrls<Event>(eventItem);
            manager.Publish(eventItem);
            manager.SaveChanges();
 
            RadScheduler1.DataSource = GetSourceItems();
        
 
        private void DeleteAppoinment(Appointment appoinment)
        
            if (appoinment.ID == null)
                return;
 
            EventsManager manager = EventsManager.GetManager();
            Event eventItem = manager.GetEvents()
                .Where(t => t.Id == (Guid)appoinment.ID)
                .FirstOrDefault();
 
            eventItem = manager.GetMaster(eventItem);
 
            manager.DeleteEvent(eventItem);
            manager.SaveChanges();
             
            RadScheduler1.DataSource = GetSourceItems();
        
 
        private string GenerateTooltip(Appointment appoinment)
        
            string tooltip = "";
 
            tooltip += String.Format("0 - 1", appoinment.Start.ToShortTimeString(), appoinment.End.ToShortTimeString());
 
            return tooltip;
        
    


CalendarControl.ascx.designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
 
namespace SitefinityWebApp
     
     
    public partial class CalendarControl
         
        /// <summary>
        /// RadAjaxLoadingPanel1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::Telerik.Web.UI.RadAjaxLoadingPanel RadAjaxLoadingPanel1;
         
        /// <summary>
        /// RadAjaxPanel1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::Telerik.Web.UI.RadAjaxPanel RadAjaxPanel1;
         
        /// <summary>
        /// RadScheduler1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::Telerik.Web.UI.RadScheduler RadScheduler1;
    


Thanks!
Duneel

Posted by Community Admin on 18-Oct-2011 00:00

Hi Duneel,

Thank you for providing me with the control logic. I've tested both using your control and a one with dummy events, and the functionality seems to be working properly. Please find attached a short video I've recorded while testing some of this functionality, and let me know if I'm missing anything. The only change that I've introduced is that I'm using a customized version of RajAjaxPanel which ensures that the Ajax requests will complete properly The custom RajAjaxPanel is built using the same approach as the one with UpdatePanel described in this blog post. For your convenience I'm attaching the sample Scheduler and custom RadAjaxPanel along with the video.

Kind regards,
Boyan Barnev
the Telerik team

[View:/cfs-file/__key/communityserver-discussions-components-files/295/307731_5F00_Controls.rar:320:240]

[View:/cfs-file/__key/communityserver-discussions-components-files/295/307732_5F00_RadScheduler_2D00_Sitefinity_2D00_Ajax.rar:320:240]

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 23-May-2012 00:00

This is a great solution.  I am having a problem with this - either my events are starting a day late in monthview or ending a day late.  I am not sure if this is to do with needing the .tolocal?

Posted by Community Admin on 23-May-2012 00:00

Hello,

You can compare the values saved into the databse for Event Start and Event End. You can also create a simple page where you use Sitefinity's API  and show all events and the above mentioned values to see if there are some time differences. EventStart and EventEnd and properties of the data item so you can put a breakpoint inside a method that binds the RadScheduler to see if there would be a difference.

Kind regards,
Ivan Dimitrov
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