This is a migrated thread and some comments may be shown as answers.

Use custom Appointment classes in RadScheduler with Web Services

1 Answer 208 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 05 Nov 2013, 08:49 AM
Hi,

I have successfully created a project with RadScheduler where I use a custom Appointment class (AllocationViewDataItem) and a custom Resource class (ExtendedResource). This project uses postbacks and a DataSource set in by calling a provider in Page_Load using the required parameters and setting the retrieved list of AllocationViewDataItems (custom appointments) as the DataSource of the scheduler.

var dataSource = DataManager.GetData(WebPart.ViewType, WebPart.DataFiltering, WebPart.ShowAllocationInLabel, selectedDate, numberOfWeeks, selectedRole);
 
Scheduler.DataSource = dataSource;

The custom appointments (AllocationViewDataItems) contain a string property called Resource that contains the key of the resource they are related to.

public class AllocationViewDataItem
    {
        public int Id { get; set; }
 
        public string Resource { get; set; }  //<------ This Property
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public Color Color { get; set; }
         
        public string CustomText { get; set; }
 
        ...
    }

The resources and appointments are connected by setting the ForeignKeyField on the ResourceType:
var rType = new ResourceType("User") { ForeignKeyField = "Resource" };
Scheduler.ResourceTypes.Add(rType);
Scheduler.GroupBy = "User";

The scheduler uses the custom appointment class by defining these properties:

<telerik:RadScheduler runat="server"
    ID="Scheduler"
    DataStartField="Start"
    DataEndField="End"
    DataSubjectField="CustomText"
    DataKeyField="Id"
    ...
    >


 This works perfectly and the resources and allocations are shown as they should.

Now, I'd like to change the project so that the data is retrieved using web services because they constant postbacks are not too pretty. I have created a branch of the project that contains a web service that calls the same DataManager and returns a list of AllocationViewDataItems (just like the GetData method in the old Page_Load that was set as DataSource). However, the appointments are no longer matched with resources based on the ForeignKeyField of the ResourceType. No appointments are shown and when I hook into the OnClientAppointmentDataBound event I can see that the appointments are databound, but their collection of Resources is empty. Below is a dummy example of the web service methods (which does not work either):

[WebMethod]
public IEnumerable<AllocationViewDataItem> GetAppointments(ExtendedSchedulerInfo schedulerInfo)
{     
    return new List<AllocationViewDataItem>
               {
                   new AllocationViewDataItem
                       {
                           Id = 1,
                           Start = DateTime.Now,
                           End = DateTime.Now.AddHours(1),
                           CustomText = "Subject",
                           Resource = "test",
                           Color = Color.Red
                       }
               };
}
 
[WebMethod]
public IEnumerable<ResourceData> GetResources(ExtendedSchedulerInfo schedulerInfo)
{
    var res = new List<ResourceData>
               {
                   new ResourceData
                       {
                           Key = "test",
                           Type = "User",
                           Text = "Test"                                 
                       }
               };
    res[0].Attributes.Add("TestAttribute", "testvalue");
    return res;
}

The Scheduler defines the use of the web service and the AllocationViewDataItems as such:

<telerik:RadScheduler runat="server"
    ID="Scheduler"
    DataStartField="Start"
    DataEndField="End"
    DataSubjectField="CustomText"
    DataKeyField="Id"
    ...
    >
<WebServiceSettings Path="/_layouts/TestProject/ProjectAllocationDataService.asmx" ResourcePopulationMode="ServerSide" />
</telerik:RadScheduler>

The custom appointments are simply not connected to the resources so they are not shown. If I use AppointmentData instead and assigns a specific ResourceData object to the Resources property it works, but would mean that I would have to redo a quite a bit of code so I would prefer not to.

Is it not possible to use the ForeignKeyField to combine a custom Appointment class to resources when using Web Services to retrieve data?

Another issue is that I can't successfully use the Attributes property of the ResourceData class. When I add an item to the Attributes collection in the web service method it is not transfered to the Resource class created behind the scenes. I have checked this by adding an item to the Attributes collection in the web service method "GetResources" and then inspecting the Resource class retrieved in the OnResourceHeaderCreated event (here the Attribute collection is empty). See the two attached images. This is an issue as I need to transfer a custom URL property to the resource to make it clickable. 
The attributes are successfully transfered from AppointmentData to the Appointment (adding attribute to AppointmentData object in web service method and retrieving the attribute value in OnClientAppointmentDataBound).

I hope you can help me with either of the two issues.

/Michael

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 08 Nov 2013, 09:40 AM
Hello,

I have attached our recommended approach for implementing such scenario. An easy and convenient way of associating appointment and resource as shown in the GetAppointments method  and load resource for each appointment. Please note that in LoadTeachers you can set a resource attribute ( a "Phone" for sample purposes) and then you can access this attribute value on the client side in the OnClientDataBound client-side event. For sample purposes it will pop-up alert box with the phone value for appointment teacher resource.


Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
WebParts for SharePoint
Asked by
Michael
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or