Skip to content

Instantly share code, notes, and snippets.

@SimonDoy
Last active May 25, 2016 04:56
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/c0d405ebe118fd9f2cc22514b09e97a3 to your computer and use it in GitHub Desktop.
Save SimonDoy/c0d405ebe118fd9f2cc22514b09e97a3 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.Threading.Tasks;
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 = null;
public InvoiceController()
: base()
{
}
private async Task Initialise()
{
_invoiceRepository = await InvoiceRepository.GetCurrent();
}
public async Task<IList<InvoiceForm>> Get()
{
IList<InvoiceForm> listOfForms = new List<InvoiceForm>();
try
{
await Initialise();
listOfForms = _invoiceRepository.GetAll();
}
catch (Exception ex)
{
throw;
}
return listOfForms;
}
[HttpGet]
// GET api/values/5
public async Task<InvoiceForm> Get(string reference)
{
InvoiceForm invoiceForm = new InvoiceNotFoundForm();
try
{
await Initialise();
invoiceForm = _invoiceRepository.Get(reference);
}
catch (Exception ex)
{
throw;
}
return invoiceForm;
}
[HttpPost]
[Route("api/invoice/add")]
// POST api/values
public async Task Post([FromBody]InvoiceForm invoice)
{
try
{
await Initialise();
await _invoiceRepository.Add(invoice);
}
catch (Exception ex)
{
throw;
}
}
[HttpPut]
// PUT api/values/5
public async Task Put(string reference, [FromBody]InvoiceForm invoice)
{
try
{
throw new NotImplementedException("Not implemented yet");
}
catch (Exception ex)
{
throw;
}
}
[HttpDelete]
// DELETE api/values/5
public async Task Delete(string reference)
{
try
{
await Initialise();
await _invoiceRepository.Remove(reference);
}
catch (Exception ex)
{
throw;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment