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;

}

}

}

 

相关文章:

  • 2021-06-01
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2021-06-25
猜你喜欢
  • 2021-10-25
  • 2021-10-14
  • 2022-02-10
  • 2021-07-27
  • 2021-12-07
  • 2021-12-16
  • 2021-11-10
相关资源
相似解决方案