diff SilverlightAsyncRestWcf/SilverlightAsyncRestWcf.Services/CarService.cs @ 118:fa4ba8943048

final version
author stevenh7776
date Sun, 27 May 2012 19:53:23 +0100
parents 9eadccc3b46c
children
line wrap: on
line diff
--- a/SilverlightAsyncRestWcf/SilverlightAsyncRestWcf.Services/CarService.cs	Sun May 27 15:06:35 2012 +0100
+++ b/SilverlightAsyncRestWcf/SilverlightAsyncRestWcf.Services/CarService.cs	Sun May 27 19:53:23 2012 +0100
@@ -1,9 +1,10 @@
 using System;
+using System.Collections.Generic;
 using System.Diagnostics.Contracts;
 using System.IO;
-using System.Runtime.Serialization.Json;
 using System.ServiceModel.Activation;
 using System.ServiceModel.Web;
+using System.Text;
 using SilverlightAsyncRestWcf.Common;
 
 namespace SilverlightAsyncRestWcf.Services
@@ -12,12 +13,10 @@
     public class CarService : IService<Car>
     {
         private readonly IRepository<Car> _repo;
-        private readonly DataContractJsonSerializer _serializer;
 
         public CarService()
         {
             _repo = new FakeCarRepository();
-            _serializer = new DataContractJsonSerializer(typeof(Car));
         }
 
         public CarService(IRepository<Car> repo)
@@ -25,32 +24,36 @@
             _repo = repo;
         }
 
-        [WebGet(UriTemplate = "Car/{id}")]
-        public string Get(string id)
+        [WebGet(UriTemplate = "Cars", ResponseFormat = WebMessageFormat.Json)]
+        public IList<Car> GetAll()
         {
-            Contract.Requires((bool)(id != null), "id != null");
-            return _repo.GetById(id).ToJSON();
+            var cars = _repo.GetAll();
+            return cars;
+        }
+
+        [WebGet(UriTemplate = "Car/{id}", ResponseFormat = WebMessageFormat.Json)]
+        public Car Get(string id)
+        {
+            var car = _repo.GetById(id);
+            return car;
         }
 
         [WebInvoke(UriTemplate = "Car", Method = "POST")]
         public void Insert(Car car)
         {
-            Contract.Requires((bool)(car != null), "car != null");
             _repo.Insert(car);
         }
 
         [WebInvoke(UriTemplate = "Car/{id}", Method = "PUT")]
         public void Update(string id, Car car)
         {
-            Contract.Requires((bool)(car != null), "car != null");
             _repo.Update(car);
         }
      
-        [WebInvoke(UriTemplate = "Car({id})", Method = "DELETE")]
+        [WebInvoke(UriTemplate = "Car/{id}", Method = "DELETE")]
         public void Delete(string id)
         {
-            Contract.Requires((bool)(id != null), "id != null");
             _repo.Delete(id);
         }
     }
-}
+}
\ No newline at end of file