Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.