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

Example of Provider interface changes in Q3 2010

1 Answer 67 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Sudha
Top achievements
Rank 1
Sudha asked on 31 Jan 2011, 05:56 PM
Is there an example showing how to implement the recent provider changes for sending additional information to the provider? I'm working on a custom provider that does NOT use an XML data source and I'm looking mainly at the Implementing A Provider That Supports Multi-valued Resources example, but it is still using the old implementation. I understand what the changes are, but I'm having trouble converting the old "GetResourceTypes" and "GetResourceByType" methods to the new "GetResources" method.

Basically I need help converting the following code to the new "GetResources" implementation. Any help would be greatly appreciated.

public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner)
{
  ResourceType[] resourceTypes = new ResourceType[2];
  resourceTypes[0] = new ResourceType("Teacher", false);
  resourceTypes[1] = new ResourceType("Student", true);
  return resourceTypes;
}
public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType)
{
  switch (resourceType)
  {
     case "Teacher" :
         return Teachers.Values;
     case "Student" :
         return Students.Values;
     default:
         throw new InvalidOperationException( "Unknown resource type: " + resourceType);
  }
}
private IDictionary<int, Resource> Teachers
{
   get
   {
       if (_teachers == null)
       {
           _teachers = new Dictionary<int, Resource>();
           foreach (Resource teacher in LoadTeachers())
           {
               _teachers.Add((int)teacher.Key, teacher);
           }
       }
       return _teachers;
   }
}
private IDictionary<int, Resource> Students
{
   get
   {
       _students = new Dictionary<int, Resource>();
       foreach (Resource student in LoadStudents())
       {
           _students.Add((int)student.Key, student);
       }
       return _students;
   }
}
private IEnumerable<Resource> LoadTeachers()
{
  List<Resource> resources = new List<Resource>();
  using (DbConnection conn = OpenConnection())
  {
      DbCommand cmd = DbFactory.CreateCommand();
      cmd.Connection = conn;
      cmd.CommandText = "SELECT [TeacherID], [Name], [Phone] FROM [DbProvider_Teachers]";
      using (DbDataReader reader = cmd.ExecuteReader())
      {
         while (reader.Read())
         {
            Resource res = new Resource();
            res.Type = "Teacher";
            res.Key = reader["TeacherID"];
            res.Text = Convert.ToString(reader[ "Name" ]);
            res.Attributes["Phone"] = Convert.ToString(reader["Phone"]);
            resources.Add(res);
         }
      }
  }
  return resources;
}
 
private IEnumerable<Resource> LoadStudents()
{
  List<Resource> resources = new List<Resource>();
  using (DbConnection conn = OpenConnection())
  {
      DbCommand cmd = DbFactory.CreateCommand();
      cmd.Connection = conn;
      cmd.CommandText = "SELECT [StudentID], [Name] FROM [DbProvider_Students]";
      using (DbDataReader reader = cmd.ExecuteReader())
      {
          while (reader.Read())
          {
              Resource res = new Resource();
              res.Type = "Student";
              res.Key = reader["StudentID"];
              res.Text = Convert.ToString(reader[ "Name" ]);
              resources.Add(res);
          }
      }
  }
  return resources;
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 02 Feb 2011, 12:30 PM
Hello Josh,

The GetResources method could look like this:

public override IDictionary<ResourceType, IEnumerable<Resource>> GetResources(ISchedulerInfo schedulerInfo)
   {
       Dictionary<ResourceType, IEnumerable<Resource>> resCollection = new Dictionary<ResourceType, IEnumerable<Resource>>();
       resCollection.Add(new ResourceType("Teacher", false), Teachers.Values);
       resCollection.Add(new ResourceType("Student", true), Students.Values);
       return resCollection;
   }

Attached is a sample for reference.


Greetings,
Peter
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Scheduler
Asked by
Sudha
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or