易简.道(ething)

爱在进行时
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MVC-REST-SilverLight 之Api\CustomerApi.cs

Posted on 2012-02-21 21:05  如是如是  阅读(131)  评论(0编辑  收藏  举报

using System.Collections.Generic;

using System.ServiceModel;

using System.ServiceModel.Web;

using RestExample.Model;

using RestExample.Web.Resources;

 

namespace RestExample.Web.Api

{

[ServiceContract]

public class CustomerApi

{

[WebGet(UriTemplate = "")]

public List<Customer> GetAll()

{

var rep = new CustomerRepository();

return rep.GetAllCustomers();

}

 

[WebGet(UriTemplate = "{id}")]

public Customer GetByID(int id)

{

var rep = new CustomerRepository();

return rep.GetSingleCustomerByID(id);

}

 

[WebInvoke(UriTemplate = "", Method = "POST")]

public Customer Post(Customer customer)

{

var rep = new CustomerRepository();

 

Customer cust = rep.AddOrUpdate(customer);

 

return cust;

}

 

[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]

public Customer Delete(int id)

{

var rep = new CustomerRepository();

var cust = rep.GetSingleCustomerByID(id);

 

rep.Delete(id);

 

return cust;

}

}

}