MVCRESTSilverLight 之Api\CustomerApi.cs

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;

}

}

}

 

 
 
作者:易简.道    
 
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/xyicheng/p/2361921.html