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

Passing parameter to GetResources wiht Webservice

5 Answers 71 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
ric c
Top achievements
Rank 1
ric c asked on 03 May 2013, 03:59 PM
Hi, 
I'm loading appointments to scheduler using: 
<WebServiceSettings Path="~/Webservices/Scheduler.asmx" ResourcePopulationMode="ServerSide" />

This is my scheduler.asmx.cs
public class MySchedulerInfo : SchedulerInfo
    {
        private int _hubID;
        public int HubID
        {
            get { return _hubID; }
            set { _hubID = value; }
        }
        private int _orderID;
        public int OrderID
        {
            get { return _orderID; }
            set { _orderID = value; }
        }
        private string _date;
        public string Date
        {
            get { return _date; }
            set { _date = value; }
        }
    }
 
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]   
    [System.Web.Script.Services.ScriptService]
    public class Scheduler : System.Web.Services.WebService
    {
        private WebServiceAppointmentController _controller;
 
        /// <summary>
        /// The WebServiceAppointmentController class is used as a facade to the SchedulerProvider.
        /// </summary>
        private WebServiceAppointmentController Controller
        {
            get
            {
                if (_controller == null)
                {
                    _controller = new WebServiceAppointmentController("MyDBSchedulerProvider");
 
                }
                return _controller;
            }
        }
 
        [WebMethod(EnableSession=true)]
        //public IEnumerable<AppointmentData> GetAppointments(SchedulerInfo schedulerInfo)
        public IEnumerable<AppointmentData> GetAppointments(MySchedulerInfo schedulerInfo)
        {
            //
            Session["schHubID"] = schedulerInfo.HubID;
            Session["schDate"] = schedulerInfo.Date;
            Session["schOrderID"] = schedulerInfo.OrderID;
            return Controller.GetAppointments(schedulerInfo);
        }
 
 
         [WebMethod(EnableSession = true)]
        //public IEnumerable<AppointmentData> UpdateAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData)
        public IEnumerable<AppointmentData> UpdateAppointment(MySchedulerInfo schedulerInfo, AppointmentData appointmentData)
        {
            Session["schHubID"] = schedulerInfo.HubID;
            Session["schDate"] = schedulerInfo.Date;
            Session["schOrderID"] = schedulerInfo.OrderID;
            return Controller.UpdateAppointment(schedulerInfo, appointmentData);
        }
 
        #region not used
        [WebMethod]
        public IEnumerable<AppointmentData> InsertAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData)
        {
            return Controller.InsertAppointment(schedulerInfo, appointmentData);
        }
 
        [WebMethod]
        public IEnumerable<AppointmentData> CreateRecurrenceException(SchedulerInfo schedulerInfo, AppointmentData recurrenceExceptionData)
        {
            return Controller.CreateRecurrenceException(schedulerInfo, recurrenceExceptionData);
        }
 
        [WebMethod]
        public IEnumerable<AppointmentData> RemoveRecurrenceExceptions(SchedulerInfo schedulerInfo, AppointmentData masterAppointmentData)
        {
            return Controller.RemoveRecurrenceExceptions(schedulerInfo, masterAppointmentData);
        }
 
        [WebMethod]
        public IEnumerable<AppointmentData> DeleteAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData, bool deleteSeries)
        {
            return Controller.DeleteAppointment(schedulerInfo, appointmentData, deleteSeries);
        }
        #endregion
 
       [WebMethod(EnableSession = true)]
        public IEnumerable<ResourceData> GetResources(MySchedulerInfo schedulerInfo)
        {
            Session["schHubID"] = schedulerInfo.HubID;
            return Controller.GetResources(schedulerInfo);
        }
    }

Within MyDBSchedulerProvider:
public class MyDbSchedulerProvider2 : DbSchedulerProviderBase
    {
        #region get Vans
        private IDictionary<int, Resource> _vans;       
 
        private IDictionary<int, Resource> Vans
        {
            get
            {
                bool load = false;
                if (_vans == null)
                {
                    load = true;
                }
                if (!load)
                {
                    //if (_vans.Count == 0)
                        load = true;
                }
                if (load)
                {
                    _vans = new Dictionary<int, Resource>();
                    foreach (Resource van in LoadVans()) <---NEED TO PASS PARAM HERE
                    {
                        _vans.Add((int)van.Key, van);
                    }
                     
                }
 
                return _vans;
            }
        }
        public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner)
        {
            ResourceType[] resourceTypes = new ResourceType[1];
            resourceTypes[0] = new ResourceType("Van", false);
            return resourceTypes;
        }

 I'm loading my resources (Vans), but I need to be able to pass a parameter (HubID) from my aspx to allow me to load the right resources.. I've tried doing this via "Session["schHubID"] = schedulerInfo.HubID;"
#region LoadVans
        private IEnumerable<Resource> LoadVans()
        {
            List<Resource> resources = new List<Resource>();
            int hubID = (int)HttpContext.Current.Session["schHubID"];
DO the load based on hubID


I'm no having much luck passing the param to the session... any ideas?

using Version 2010.1.309.35
Thanks

5 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 08 May 2013, 01:27 PM
Hello,

I would suggest reviewing our help article that demonstrates how you can send some additional information from your aspx page to your web service implementation.

Regards,
Boyan Dimitrov
the Telerik team
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 their blog feed now.
0
ric c
Top achievements
Rank 1
answered on 08 May 2013, 02:02 PM
Hi, thanks for the reply however I alreday using the basis of that article, my question was how to pass a parameter to the function that loads the resources eg:

private IEnumerable<
Resource> LoadVans()

Do you have any pointers?
0
Boyan Dimitrov
Telerik team
answered on 13 May 2013, 02:39 PM
Hello,

I have attached a sample project that implements a sample scenario that show how you can pass a parameter from the aspx file and can be used in the LoadTeachers method. An easy and conveninient way of achieving such functionality would be to declare a MySchedulerInfo variable that will be shared among the properties and methods of the MyDbSchedulerProvider class implementation. This way you can access it and pass it as parameter or use its value in the method implementation.
//code behind
public class MyDbSchedulerProvider : DbSchedulerProviderBase
{
    private MySchedulerInfo customParameter = new MySchedulerInfo();
 
    private IDictionary<int, Resource> _teachers;
   ....
 
    private IDictionary<int, Resource> Teachers
    {
        get
        {
            if (_teachers == null)
            {
                _teachers = new Dictionary<int, Resource>();
                foreach (Resource teacher in LoadTeachers(customParameter))
                {
                    _teachers.Add((int)teacher.Key, teacher);
                }
            }
 
            return _teachers;
        }
    }
 
public override IEnumerable<Appointment> GetAppointments(ISchedulerInfo shedulerInfo)
    {
       ...
        customParameter = shedulerInfo as MySchedulerInfo;
 
        List<Appointment> appointments = new List<Appointment>();
 
       .........
 
        return appointments;
    }
private IEnumerable<Resource> LoadTeachers(MySchedulerInfo customParam)
    {
        List<Resource> resources = new List<Resource>();
 
        // here you can use your customParam.TeacherID value that is passed from your .aspx file
 
        .....
    }
}

Hope that this will be helpful.

Regards,
Boyan Dimitrov
the Telerik team
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 their blog feed now.
0
Prava kafle
Top achievements
Rank 1
answered on 04 Sep 2013, 12:57 PM
Hi Boyan,
I followed your sample and tried to use custom parameter to filter resources used by Radscheduler.
private IDictionary<int, Resource> Teachers was set even before  "GetAppointments(ISchedulerInfo shedulerInfo) was called.
Since customParameter  was null, LoadTeachers(customParameter) threw an error.

Looks like I am missing something, can you tell me how can I set  customParameter before calling LoadTeachers(customParameter)


Thanks,
Prava


0
Boyan Dimitrov
Telerik team
answered on 05 Sep 2013, 04:02 PM
Hello,

I have inspected the problem once again and concluded that no filtering of the resource on RadScheduler is possible when it is bound to web service. Please excuse us for the misleading information provided in this form thread.

The issue is event logged in the feedback portal as a feature request and you can follow it and vote for it here.

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
Scheduler
Asked by
ric c
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
ric c
Top achievements
Rank 1
Prava kafle
Top achievements
Rank 1
Share this question
or