Last active
May 20, 2016 20:25
-
-
Save SimonDoy/f50954a8e00e91466edc11e13a81c36b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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