Initial git push
This commit is contained in:
85
H_PLUS_Sports/Controllers/CustomersController.cs
Normal file
85
H_PLUS_Sports/Controllers/CustomersController.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using H_PLUS_Sports.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace H_PLUS_Sports.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/Customers")]
|
||||
// [ApiController]
|
||||
public class CustomersController : ControllerBase
|
||||
{
|
||||
private readonly H_Plus_SportsContext _context;
|
||||
|
||||
public CustomersController(H_Plus_SportsContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetCustomer()
|
||||
{
|
||||
var results = new ObjectResult(_context.Customer)
|
||||
{
|
||||
StatusCode = (int)HttpStatusCode.OK
|
||||
};
|
||||
Request.HttpContext.Response.Headers.Add("X-Total-Count", _context.Customer.Count().ToString());
|
||||
return results;
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetCustomer")]
|
||||
public async Task<IActionResult> GetCustomer([FromRoute] int id)
|
||||
{
|
||||
if ((CustomerExists(id)))
|
||||
{
|
||||
var customer = await _context.Customer.SingleOrDefaultAsync(m => m.CustomerId == id);
|
||||
return Ok(customer);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
private bool CustomerExists(int id)
|
||||
{
|
||||
return _context.Customer.Any(c => c.CustomerId == id);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostCustomer([FromBody] Customer customer)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
_context.Customer.Add(customer);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction("getCustomer", new { id = customer.CustomerId }, customer);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutCustomer([FromRoute] int id, [FromBody] Customer customer)
|
||||
{
|
||||
_context.Entry(customer).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(customer);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteCustomer([FromRoute] int id)
|
||||
{
|
||||
var customer = await _context.Customer.SingleOrDefaultAsync(m => m.CustomerId == id);
|
||||
_context.Customer.Remove(customer);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(customer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
62
H_PLUS_Sports/Controllers/OrderItemsController.cs
Normal file
62
H_PLUS_Sports/Controllers/OrderItemsController.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using H_PLUS_Sports.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HPlusSportsAPI.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/OrderItems")]
|
||||
public class OrderItemsController : Controller
|
||||
{
|
||||
private readonly H_Plus_SportsContext _context;
|
||||
|
||||
public OrderItemsController(H_Plus_SportsContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetOrderItem()
|
||||
{
|
||||
return new ObjectResult(_context.OrderItem);
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetOrderItem")]
|
||||
public async Task<IActionResult> GetOrderItem([FromRoute] int id)
|
||||
{
|
||||
var orderItem = await _context.OrderItem.SingleOrDefaultAsync(m => m.OrderItemId == id);
|
||||
return Ok(orderItem);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostOrderItem([FromBody] OrderItem orderItem)
|
||||
{
|
||||
_context.OrderItem.Add(orderItem);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction("getOrderItem", new { id = orderItem.OrderItemId }, orderItem);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutOrderItem([FromRoute] int id, [FromBody] OrderItem orderItem)
|
||||
{
|
||||
_context.Entry(orderItem).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(orderItem);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
|
||||
public async Task<IActionResult> DeleteOrderItem([FromRoute] int id)
|
||||
{
|
||||
var orderItem = await _context.OrderItem.SingleOrDefaultAsync(m => m.OrderItemId== id);
|
||||
_context.OrderItem.Remove(orderItem);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(orderItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
H_PLUS_Sports/Controllers/OrdersController.cs
Normal file
61
H_PLUS_Sports/Controllers/OrdersController.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using H_PLUS_Sports.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HPlusSportsAPI.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/Orders")]
|
||||
public class OrdersController : Controller
|
||||
{
|
||||
private readonly H_Plus_SportsContext _context;
|
||||
|
||||
public OrdersController(H_Plus_SportsContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetOrder()
|
||||
{
|
||||
return new ObjectResult(_context.Order);
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetOrder")]
|
||||
public async Task<IActionResult> GetOrder([FromRoute] int id)
|
||||
{
|
||||
var order = await _context.Order.SingleOrDefaultAsync(m => m.OrderId == id);
|
||||
return Ok(order);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostOrder([FromBody] Order order)
|
||||
{
|
||||
_context.Add(order);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction("getOrder", new { id = order.OrderId }, order);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutOrder([FromRoute] int id, [FromBody] Order order)
|
||||
{
|
||||
_context.Entry(order).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(order);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteOrder([FromRoute] int id)
|
||||
{
|
||||
var order = await _context.Order.SingleOrDefaultAsync(m => m.OrderId== id);
|
||||
_context.Order.Remove(order);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
H_PLUS_Sports/Controllers/ProductsController.cs
Normal file
61
H_PLUS_Sports/Controllers/ProductsController.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using H_PLUS_Sports.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HPlusSportsAPI.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/Products")]
|
||||
public class ProductsController : Controller
|
||||
{
|
||||
private readonly H_Plus_SportsContext _context;
|
||||
|
||||
public ProductsController(H_Plus_SportsContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetProduct()
|
||||
{
|
||||
return new ObjectResult(_context.Product);
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetProduct")]
|
||||
public async Task<IActionResult> GetProduct([FromRoute] string id)
|
||||
{
|
||||
var product = await _context.Product.SingleOrDefaultAsync(m => m.ProductId == id);
|
||||
return Ok(product);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostProduct([FromBody] Product product)
|
||||
{
|
||||
_context.Product.Add(product);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction("getProduct", new { id = product.ProductId }, product);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutProduct([FromRoute] string id, [FromBody] Product product)
|
||||
{
|
||||
_context.Entry(product).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(product);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteProduct([FromRoute] string id)
|
||||
{
|
||||
var product = await _context.Product.SingleOrDefaultAsync(m => m.ProductId == id);
|
||||
_context.Product.Remove(product);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(product);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
H_PLUS_Sports/Controllers/SalespersonsController.cs
Normal file
61
H_PLUS_Sports/Controllers/SalespersonsController.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using H_PLUS_Sports.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HPlusSportsAPI.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/Salespersons")]
|
||||
public class SalespersonsController : Controller
|
||||
{
|
||||
private readonly H_Plus_SportsContext _context;
|
||||
|
||||
public SalespersonsController(H_Plus_SportsContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetSalesperson()
|
||||
{
|
||||
return new ObjectResult(_context.Salesperson);
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetSalesPerson")]
|
||||
public async Task<IActionResult> GetSalesperson([FromRoute] int id)
|
||||
{
|
||||
var salesPerson = await _context.Salesperson.SingleOrDefaultAsync(m => m.SalespersonId== id);
|
||||
return Ok(salesPerson);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostSalesperson([FromBody] Salesperson salesPerson)
|
||||
{
|
||||
_context.Salesperson.Add(salesPerson);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction("getSalesPerson", new { id = salesPerson.SalespersonId}, salesPerson);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutSalesperson([FromRoute] int id, [FromBody] Salesperson salesPerson)
|
||||
{
|
||||
_context.Entry(salesPerson).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(salesPerson);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteSalesperson([FromRoute] int id)
|
||||
{
|
||||
var salesPerson = await _context.Salesperson.SingleOrDefaultAsync(m => m.SalespersonId == id);
|
||||
_context.Salesperson.Remove(salesPerson);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(salesPerson);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user