1: using System;
2: using System.Web;
3: using System.Web.Services;
4: using System.Web.Services.Protocols;
5: using System.Web.Script.Services;
6: using System.Collections.Generic;
7: using System.Linq;
8:
9: public class Car
10: {
11: public int ID;
12: public string Make;
13: public string Model;
14: public int Year;
15: public int Doors;
16: public string Color;
17: public float Price;
18: public int Mileage;
19: }
20:
21: /// <summary>
22: /// Summary description for CarService
23: /// </summary>
24: [WebService(Namespace = "http://tempuri.org/")]
25: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
26: [ScriptService]
27: public class CarService : WebService
28: {
29: List<Car> Cars = new List<Car>{
30: new Car{ID=1,Make="Audi",Model="A4",Year=1995,Doors=4,Color="Red",Price=2995f,Mileage=122458},
31: new Car{ID=2,Make="Ford",Model="Focus",Year=2002,Doors=5,Color="Black",Price=3250f,Mileage=68500},
32: new Car{ID=3,Make="BMW",Model="5 Series",Year=2006,Doors=4,Color="Grey",Price=24950f,Mileage=19500},
33: new Car{ID=4,Make="Renault",Model="Laguna",Year=2000,Doors=5,Color="Red",Price=3995f,Mileage=82600},
34: new Car{ID=5,Make="Toyota",Model="Previa",Year=1998,Doors=5,Color="Green",Price=2695f,Mileage=72400},
35: new Car{ID=6,Make="Mini",Model="Cooper",Year=2005,Doors=2,Color="Grey",Price=9850f,Mileage=19800},
36: new Car{ID=7,Make="Mazda",Model="MX 5",Year=2003,Doors=2,Color="Silver",Price=6995f,Mileage=51988},
37: new Car{ID=8,Make="Ford",Model="Fiesta",Year=2004,Doors=3,Color="Red",Price=3759f,Mileage=50000},
38: new Car{ID=9,Make="Honda",Model="Accord",Year=1997,Doors=4,Color="Silver",Price=1995f,Mileage=99750},
39: new Car{ID=10,Make="Audi",Model="A6",Year=2005,Doors=5,Color="Silver",Price=22995f,Mileage=25400},
40: new Car{ID=11,Make="Jaguar",Model="XJS",Year=1992,Doors=4,Color="Green",Price=3450,Mileage=92000},
41: new Car{ID=12,Make="Jaguar",Model="X Type",Year=2006,Doors=4,Color="Grey",Price=9950f,Mileage=17000},
42: new Car{ID=13,Make="Renault",Model="Megane",Year=2007,Doors=5,Color="Red",Price=8995f,Mileage=8500},
43: new Car{ID=14,Make="Peugeot",Model="406",Year=2003,Doors=4,Color="Grey",Price=3450f,Mileage=86000},
44: new Car{ID=15,Make="Mini",Model="Cooper S",Year=2008,Doors=2,Color="Black",Price=14850f,Mileage=9500},
45: new Car{ID=16,Make="Mazda",Model="5",Year=2006,Doors=5,Color="Silver",Price=6940f,Mileage=53500},
46: new Car{ID=17,Make="Vauxhall",Model="Vectra",Year=2007,Doors=5,Color="White",Price=13750f,Mileage=31000},
47: new Car{ID=18,Make="Ford",Model="Puma",Year=1998,Doors=3,Color="Silver",Price=2995f,Mileage=84500},
48: new Car{ID=19,Make="Ford",Model="Ka",Year=2004,Doors=3,Color="Red",Price=2995f,Mileage=61000},
49: new Car{ID=20,Make="Ford",Model="Focus",Year=2007,Doors=5,Color="Blue",Price=9950f,Mileage=19000},
50: new Car{ID=21,Make="BMW",Model="3 Series",Year=2001,Doors=4,Color="White",Price=5950f,Mileage=98000},
51: new Car{ID=22,Make="Citroen",Model="C5",Year=2005,Doors=5,Color="Silver",Price=5995f,Mileage=38400},
52: new Car{ID=23,Make="Toyota",Model="Corolla T3",Year=2004,Doors=5,Color="Blue",Price=5995f,Mileage=71000},
53: new Car{ID=24,Make="Toyota",Model="Yaris",Year=2005,Doors=3,Color="Grey",Price=5350f,Mileage=39000},
54: new Car{ID=25,Make="Porsche",Model="911",Year=2003,Doors=2,Color="Red",Price=16995f,Mileage=88000},
55: new Car{ID=26,Make="Ford",Model="Fiesta",Year=2004,Doors=3,Color="Red",Price=5759f,Mileage=49000},
56: new Car{ID=27,Make="Honda",Model="Accord",Year=1996,Doors=4,Color="Black",Price=1995f,Mileage=105000},
57: new Car{ID=28,Make="Audi",Model="A3 Avant",Year=2005,Doors=5,Color="Blue",Price=12995f,Mileage=22458},
58: new Car{ID=29,Make="Ford",Model="Mondeo",Year=2007,Doors=5,Color="Gold",Price=12250f,Mileage=8500},
59: new Car{ID=30,Make="BMW",Model="1 Series",Year=2006,Doors=4,Color="Black",Price=16950f,Mileage=19500},
60: new Car{ID=31,Make="Renault",Model="Clio",Year=2005,Doors=3,Color="Red",Price=5995f,Mileage=32600},
61: new Car{ID=32,Make="Toyota",Model="Verso",Year=2008,Doors=5,Color="White",Price=12995f,Mileage=5800},
62: new Car{ID=33,Make="Mini",Model="Cooper",Year=2003,Doors=2,Color="Black",Price=7950f,Mileage=36800},
63: new Car{ID=34,Make="Mazda",Model="6",Year=2007,Doors=4,Color="Blue",Price=16995f,Mileage=11300},
64: new Car{ID=35,Make="Ford",Model="Mondeo",Year=2004,Doors=5,Color="Green",Price=8759f,Mileage=66000},
65: new Car{ID=36,Make="Honda",Model="Civic",Year=1997,Doors=4,Color="Grey",Price=1995f,Mileage=99750},
66: new Car{ID=37,Make="Audi",Model="Q7",Year=2005,Doors=5,Color="Black",Price=22995f,Mileage=25400},
67: new Car{ID=38,Make="Jaguar",Model="XK8",Year=1992,Doors=4,Color="Blue",Price=3450,Mileage=92000},
68: new Car{ID=39,Make="Jaguar",Model="S Type",Year=2006,Doors=4,Color="Red",Price=9950f,Mileage=17000},
69: new Car{ID=40,Make="Renault",Model="Megane",Year=2007,Doors=5,Color="Yellow",Price=8995f,Mileage=8500},
70: new Car{ID=41,Make="Peugeot",Model="406",Year=2003,Doors=4,Color="White",Price=3450f,Mileage=86000},
71: new Car{ID=42,Make="Mini",Model="Cooper",Year=2008,Doors=2,Color="Red",Price=14850f,Mileage=9500},
72: new Car{ID=43,Make="Mazda",Model="5",Year=2006,Doors=5,Color="White",Price=6940f,Mileage=53500},
73: new Car{ID=44,Make="Vauxhall",Model="Vectra",Year=2007,Doors=5,Color="Blue",Price=13750f,Mileage=31000},
74: new Car{ID=45,Make="Ford",Model="Puma",Year=1998,Doors=3,Color="Red",Price=2995f,Mileage=84500},
75: new Car{ID=46,Make="Ford",Model="Puma",Year=2004,Doors=3,Color="Red",Price=2995f,Mileage=61000},
76: new Car{ID=47,Make="Ford",Model="Focus",Year=2007,Doors=5,Color="Grey",Price=9950f,Mileage=19000},
77: new Car{ID=48,Make="BMW",Model="3 Series",Year=2001,Doors=4,Color="Red",Price=5950f,Mileage=98000},
78: new Car{ID=49,Make="Citroen",Model="C5",Year=2005,Doors=5,Color="Yellow",Price=5995f,Mileage=38400},
79: new Car{ID=50,Make="Toyota",Model="Corolla T3",Year=2004,Doors=5,Color="Red",Price=5995f,Mileage=71000},
80: new Car{ID=51,Make="Toyota",Model="Yaris",Year=2005,Doors=3,Color="Black",Price=5350f,Mileage=39000},
81: new Car{ID=52,Make="Porsche",Model="911",Year=2003,Doors=2,Color="White",Price=16995f,Mileage=88000},
82: new Car{ID=53,Make="Ford",Model="Fiesta",Year=2004,Doors=3,Color="Grey",Price=5759f,Mileage=49000},
83: new Car{ID=54,Make="Honda",Model="Accord",Year=1996,Doors=4,Color="Green",Price=1995f,Mileage=105000}
84: };
85:
86: [WebMethod]
87: public List<Car> GetCarsByDoors(int doors)
88: {
89: var query = from c in Cars
90: where c.Doors == doors
91: select c;
92: return query.ToList();
93: }
94:
95: [WebMethod]
96: public List<Car> GetAllCars()
97: {
98: return Cars;
99: }
100:
101: [WebMethod]
102: public List<string> GetCarMakes()
103: {
104: var query = (from c in Cars
105: orderby c.Make
106: select c.Make).Distinct();
107: return query.ToList();
108: }
109:
110: [WebMethod]
111: public List<string> GetCarsByModel(string make)
112: {
113: var query = (from c in Cars
114: where c.Make == make
115: orderby c.Model
116: select c.Model).Distinct();
117: return query.ToList();
118: }
119:
120: [WebMethod]
121: public List<string> GetCarsByColor(string make, string model)
122: {
123: var query = (from c in Cars
124: where c.Make == make && c.Model == model
125: orderby c.Color
126: select c.Color).Distinct();
127: return query.ToList();
128: }
129:
130: [WebMethod]
131: public List<Car> GetCarListByColor(string make, string model, string color)
132: {
133: var query = from c in Cars
134: where (c.Make == make &&
135: c.Model == model &&
136: c.Color == color)
137: select c;
138: return query.ToList();
139: }
140: }