Skip to content

Instantly share code, notes, and snippets.

@AbhinavPradeep
Created February 10, 2020 12:00
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 AbhinavPradeep/802194b7d2e56bc1c74de8e6c2819339 to your computer and use it in GitHub Desktop.
Save AbhinavPradeep/802194b7d2e56bc1c74de8e6c2819339 to your computer and use it in GitHub Desktop.
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using Theta.Customers.API.Configuration;
using Theta.Customers.Models;
using Theta.Customers.Repository;
namespace Theta.Customers.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class CustomersController : ControllerBase
{
IOptions<CustomerSettings> settings;
public CustomersController(IOptions<CustomerSettings> settings)
{
this.settings = settings;
}
[HttpGet]
public JsonResult ListPeople()
{
CustomerRepos CustomerRepo = new CustomerRepos(settings.Value.ConnectionString);
var customers = CustomerRepo.GetAllCustomers();
return new JsonResult(customers);
}
[HttpGet("{personID}")]
public List<Customer> ListCustomer(int customerID)
{
CustomerRepos CustomerRepo = new CustomerRepos(settings.Value.ConnectionString);
var customer = CustomerRepo.GetCustomer(customerID);
return customer;
}
[HttpDelete("{personID}")]
public long DeleteCustomer(int customerID)
{
CustomerRepos CustomerRepo = new CustomerRepos(settings.Value.ConnectionString);
var DeletedCount = CustomerRepo.DeleteCustomer(customerID);
return DeletedCount;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment