2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / System.Web.DynamicData / Test / DataObjects / EmployeeDynamicDataContainer.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Web;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8
9 using MonoTests.DataSource;
10
11 namespace MonoTests.DataObjects
12 {
13     public class EmployeeDynamicDataContainer : DynamicDataContainer <List <Employee>>
14     {
15         public override Type ContainedType
16         {
17             get
18             {
19                 return typeof (Employee);
20             }
21         }
22
23         public EmployeeDynamicDataContainer ()
24             : this (null)
25         {
26         }
27
28         public EmployeeDynamicDataContainer (List<Employee> data)
29             : base (data)
30         {
31             if (data == null)
32                 PopulateWithData ();
33         }
34
35         void PopulateWithData ()
36         {
37             Data = new List<Employee> {
38                 new Employee { FirstName = "Marek", LastName = "Habersack" }
39             };
40         }
41
42         public override int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
43         {
44             throw new NotImplementedException ();
45         }
46
47         public override int Insert (IDictionary values)
48         {
49             throw new NotImplementedException ();
50         }
51
52         public override int Delete (IDictionary keys, IDictionary oldValues)
53         {
54             throw new NotImplementedException ();
55         }
56
57         public override IEnumerable Select (DataSourceSelectArguments args, string where, ParameterCollection whereParams)
58         {
59             List<Employee> data = Data;
60             int count = data == null ? 0 : data.Count;
61
62             if (args.RetrieveTotalRowCount)
63                 args.TotalRowCount = count;
64
65             int startIndex = args.StartRowIndex;
66             if (count == 0 || count < startIndex)
67                 return new Employee[0];
68
69             int max = args.MaximumRows;
70             if (max == 0 || max > count)
71                 max = count;
72             max -= startIndex;
73
74             var ret = new List<Employee> ();
75             ret.AddRange (data.GetRange (args.StartRowIndex, max));
76
77             return ret;
78         }
79
80         public override List<DynamicDataTable> GetTables ()
81         {
82             var ret = new List<DynamicDataTable> ();
83             ret.Add (new EmployeeTable ());
84
85             return ret;
86         }
87     }
88 }