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;
}
}
}