Skip to content

Instantly share code, notes, and snippets.

@SimonDoy
Last active May 20, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonDoy/f50954a8e00e91466edc11e13a81c36b to your computer and use it in GitHub Desktop.
Save SimonDoy/f50954a8e00e91466edc11e13a81c36b to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Itsp365.InvoiceFormApp.Api.Models.Entities;
using Itsp365.InvoiceFormApp.Api.Repositories;
namespace Itsp365.InvoiceFormApp.Api.Controllers
{
[Authorize()]
public class InvoiceController : ApiController
{
private InvoiceRepository _invoiceRepository = InvoiceRepository.GetCurrent();
// GET api/values
public IEnumerable<InvoiceForm> Get()
{
return _invoiceRepository.GetAll();
}
// GET api/values/5
public InvoiceForm Get(int id)
{
var invoiceForm = Get().FirstOrDefault(i => i.Id == id);
if (invoiceForm == null)
{
invoiceForm = new InvoiceNotFoundForm();
}
return invoiceForm;
}
[HttpGet]
// GET api/values/5
public InvoiceForm Get(string reference)
{
var invoiceForm = Get().FirstOrDefault(i => i.Reference == reference);
if (invoiceForm == null)
{
invoiceForm = new InvoiceNotFoundForm();
}
return invoiceForm;
}
[HttpPost]
[Route("api/invoice/add")]
// POST api/values
public void Post([FromBody]InvoiceForm invoice)
{
_invoiceRepository.Add(invoice);
}
[HttpPut]
// PUT api/values/5
public void Put(string reference, [FromBody]InvoiceForm invoice)
{
_invoiceRepository.Update(invoice);
}
[HttpDelete]
// DELETE api/values/5
public void Delete(int id)
{
_invoiceRepository.Remove(id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment