From 07e2d6ef7e1f7dd61d67bafc0bd91e972ff4dad0 Mon Sep 17 00:00:00 2001 From: espent1004 Date: Mon, 20 Jan 2020 10:14:10 +0100 Subject: [PATCH] Endpoint --- .../ShippingInformationsController.cs | 106 ++++++++++++++++++ .../TenantACustomisations.csproj | 1 + 2 files changed, 107 insertions(+) create mode 100644 src/Services/TenantCustomisations/TenantACustomisations/Controllers/ShippingInformationsController.cs diff --git a/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ShippingInformationsController.cs b/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ShippingInformationsController.cs new file mode 100644 index 000000000..a62c1c98e --- /dev/null +++ b/src/Services/TenantCustomisations/TenantACustomisations/Controllers/ShippingInformationsController.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using TenantACustomisations.Database; +using TenantACustomisations.ExternalServices; + +namespace TenantACustomisations.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ShippingInformationsController : ControllerBase + { + private readonly TenantAContext _context; + + public ShippingInformationsController(TenantAContext context) + { + _context = context; + } + + // GET: api/ShippingInformations + [HttpGet] + public async Task>> GetShippingInformation() + { + return await _context.ShippingInformation.ToListAsync(); + } + + // GET: api/ShippingInformations/5 + [HttpGet("{id}")] + public async Task> GetShippingInformation(int id) + { + var shippingInformation = await _context.ShippingInformation.FindAsync(id); + + if (shippingInformation == null) + { + return NotFound(); + } + + return shippingInformation; + } + + // PUT: api/ShippingInformations/5 + [HttpPut("{id}")] + public async Task PutShippingInformation(int id, ShippingInformation shippingInformation) + { + if (id != shippingInformation.ShippingInformationId) + { + return BadRequest(); + } + + _context.Entry(shippingInformation).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!ShippingInformationExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/ShippingInformations + [HttpPost] + public async Task> PostShippingInformation(ShippingInformation shippingInformation) + { + _context.ShippingInformation.Add(shippingInformation); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetShippingInformation", new { id = shippingInformation.ShippingInformationId }, shippingInformation); + } + + // DELETE: api/ShippingInformations/5 + [HttpDelete("{id}")] + public async Task> DeleteShippingInformation(int id) + { + var shippingInformation = await _context.ShippingInformation.FindAsync(id); + if (shippingInformation == null) + { + return NotFound(); + } + + _context.ShippingInformation.Remove(shippingInformation); + await _context.SaveChangesAsync(); + + return shippingInformation; + } + + private bool ShippingInformationExists(int id) + { + return _context.ShippingInformation.Any(e => e.ShippingInformationId == id); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj b/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj index d21ad07f5..637a02603 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj +++ b/src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj @@ -28,6 +28,7 @@ +