117
|
1 using System;
|
118
|
2 using System.Collections.Generic;
|
117
|
3 using System.Diagnostics.Contracts;
|
|
4 using System.IO;
|
|
5 using System.ServiceModel.Activation;
|
|
6 using System.ServiceModel.Web;
|
118
|
7 using System.Text;
|
117
|
8 using SilverlightAsyncRestWcf.Common;
|
|
9
|
|
10 namespace SilverlightAsyncRestWcf.Services
|
|
11 {
|
|
12 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
|
13 public class CarService : IService<Car>
|
|
14 {
|
|
15 private readonly IRepository<Car> _repo;
|
|
16
|
|
17 public CarService()
|
|
18 {
|
|
19 _repo = new FakeCarRepository();
|
|
20 }
|
|
21
|
|
22 public CarService(IRepository<Car> repo)
|
|
23 {
|
|
24 _repo = repo;
|
|
25 }
|
|
26
|
118
|
27 [WebGet(UriTemplate = "Cars", ResponseFormat = WebMessageFormat.Json)]
|
|
28 public IList<Car> GetAll()
|
117
|
29 {
|
118
|
30 var cars = _repo.GetAll();
|
|
31 return cars;
|
|
32 }
|
|
33
|
|
34 [WebGet(UriTemplate = "Car/{id}", ResponseFormat = WebMessageFormat.Json)]
|
|
35 public Car Get(string id)
|
|
36 {
|
|
37 var car = _repo.GetById(id);
|
|
38 return car;
|
117
|
39 }
|
|
40
|
|
41 [WebInvoke(UriTemplate = "Car", Method = "POST")]
|
|
42 public void Insert(Car car)
|
|
43 {
|
|
44 _repo.Insert(car);
|
|
45 }
|
|
46
|
|
47 [WebInvoke(UriTemplate = "Car/{id}", Method = "PUT")]
|
|
48 public void Update(string id, Car car)
|
|
49 {
|
|
50 _repo.Update(car);
|
|
51 }
|
|
52
|
118
|
53 [WebInvoke(UriTemplate = "Car/{id}", Method = "DELETE")]
|
117
|
54 public void Delete(string id)
|
|
55 {
|
|
56 _repo.Delete(id);
|
|
57 }
|
|
58 }
|
118
|
59 } |