using System.Collections.Generic;
using System.Web.Script.Services;
using System.Web.Services;
using System.Configuration;
using System.Data.Common;
using Telerik.Web.UI;


public class MySchedulerInfo : SchedulerInfo
{
    public string FilterValue
    {
        get;
        set;
    }
}

[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class SchedulerWebService : WebService
{
    private WebServiceAppointmentController _controller;
    //private MySchedulerInfo localSchedulerInfo;
    private MyDbSchedulerProvider _provider;
    private MyDbSchedulerProvider Provider
    {
        get
        {
            if (_provider == null)
            {
                var connString = ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString;
                var factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
                _provider = new MyDbSchedulerProvider() { ConnectionString = connString, DbFactory = factory, PersistChanges= true };
            }
            return _provider;
        }
    }

    /// <summary>
    /// The WebServiceAppointmentController class is used as a facade to the SchedulerProvider.
    /// </summary>
    private WebServiceAppointmentController Controller
    {
        get
        {
            if (_controller == null)
            {
                _controller = new WebServiceAppointmentController(Provider);
            }

            return _controller;
        }
    }

    [WebMethod]
    public IEnumerable<AppointmentData> GetAppointments(MySchedulerInfo schedulerInfo)
    {
        Provider.FilterValue = schedulerInfo.FilterValue;
        return Controller.GetAppointments(schedulerInfo);
    }

    [WebMethod]
    public IEnumerable<AppointmentData> InsertAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData)
    {
        return Controller.InsertAppointment(schedulerInfo, appointmentData);
    }

    [WebMethod]
    public IEnumerable<AppointmentData> UpdateAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData)
    {
        return Controller.UpdateAppointment(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);
    }

    [WebMethod]
    public IEnumerable<ResourceData> GetResources(SchedulerInfo schedulerInfo)
    {
        return Controller.GetResources(schedulerInfo);
    }
}