diff --git a/Areas/Admin/Controllers/OrderItemController.cs b/Areas/Admin/Controllers/OrderItemController.cs new file mode 100644 index 0000000..1f6c162 --- /dev/null +++ b/Areas/Admin/Controllers/OrderItemController.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; +using pwt_0x01_ng.Models; +using pwt_0x01_ng.Models.Database; + +namespace pwt_0x01_ng.Areas.Admin.Controllers +{ + [Area("Admin")] + public class OrderItemController : Controller + { + private readonly DBContext _context; + + public OrderItemController(DBContext context) + { + _context = context; + } + + // GET: Admin/OrderItem + public async Task Index() + { + var dBContext = _context.OrderItem.Include(o => o.Order).Include(o => o.Product); + return View(await dBContext.ToListAsync()); + } + + // GET: Admin/OrderItem/Details/5 + public async Task Details(int? id) + { + if (id == null) + { + return NotFound(); + } + + var orderItem = await _context.OrderItem + .Include(o => o.Order) + .Include(o => o.Product) + .FirstOrDefaultAsync(m => m.id == id); + if (orderItem == null) + { + return NotFound(); + } + + return View(orderItem); + } + + // GET: Admin/OrderItem/Create + public IActionResult Create() + { + ViewData["Order_id"] = new SelectList(_context.Order, "id", "Order_Number"); + ViewData["Product_id"] = new SelectList(_context.Product, "id", "Description"); + return View(); + } + + // POST: Admin/OrderItem/Create + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create([Bind("Order_id,Product_id,Amount,Price,id,Created,Updated")] OrderItem orderItem) + { + if (ModelState.IsValid) + { + _context.Add(orderItem); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + ViewData["Order_id"] = new SelectList(_context.Order, "id", "Order_Number", orderItem.Order_id); + ViewData["Product_id"] = new SelectList(_context.Product, "id", "Description", orderItem.Product_id); + return View(orderItem); + } + + // GET: Admin/OrderItem/Edit/5 + public async Task Edit(int? id) + { + if (id == null) + { + return NotFound(); + } + + var orderItem = await _context.OrderItem.FindAsync(id); + if (orderItem == null) + { + return NotFound(); + } + ViewData["Order_id"] = new SelectList(_context.Order, "id", "Order_Number", orderItem.Order_id); + ViewData["Product_id"] = new SelectList(_context.Product, "id", "Description", orderItem.Product_id); + return View(orderItem); + } + + // POST: Admin/OrderItem/Edit/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("Order_id,Product_id,Amount,Price,id,Created,Updated")] OrderItem orderItem) + { + if (id != orderItem.id) + { + return NotFound(); + } + + if (ModelState.IsValid) + { + try + { + _context.Update(orderItem); + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!OrderItemExists(orderItem.id)) + { + return NotFound(); + } + else + { + throw; + } + } + return RedirectToAction(nameof(Index)); + } + ViewData["Order_id"] = new SelectList(_context.Order, "id", "Order_Number", orderItem.Order_id); + ViewData["Product_id"] = new SelectList(_context.Product, "id", "Description", orderItem.Product_id); + return View(orderItem); + } + + // GET: Admin/OrderItem/Delete/5 + public async Task Delete(int? id) + { + if (id == null) + { + return NotFound(); + } + + var orderItem = await _context.OrderItem + .Include(o => o.Order) + .Include(o => o.Product) + .FirstOrDefaultAsync(m => m.id == id); + if (orderItem == null) + { + return NotFound(); + } + + return View(orderItem); + } + + // POST: Admin/OrderItem/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + var orderItem = await _context.OrderItem.FindAsync(id); + _context.OrderItem.Remove(orderItem); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + private bool OrderItemExists(int id) + { + return _context.OrderItem.Any(e => e.id == id); + } + } +} diff --git a/Areas/Admin/Controllers/OrdersController.cs b/Areas/Admin/Controllers/OrdersController.cs new file mode 100644 index 0000000..946571f --- /dev/null +++ b/Areas/Admin/Controllers/OrdersController.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; +using pwt_0x01_ng.Models; +using pwt_0x01_ng.Models.Database; + +namespace pwt_0x01_ng.Areas.Admin.Controllers +{ + [Area("Admin")] + public class OrdersController : Controller + { + private readonly DBContext _context; + + public OrdersController(DBContext context) + { + _context = context; + } + + // GET: Admin/Orders + public async Task Index() + { + return View(await _context.Order.ToListAsync()); + } + + // GET: Admin/Orders/Details/5 + public async Task Details(int? id) + { + if (id == null) + { + return NotFound(); + } + + var order = await _context.Order + .FirstOrDefaultAsync(m => m.id == id); + if (order == null) + { + return NotFound(); + } + + return View(order); + } + + // GET: Admin/Orders/Create + public IActionResult Create() + { + return View(); + } + + // POST: Admin/Orders/Create + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create([Bind("Order_Number,id,Created,Updated")] Order order) + { + if (ModelState.IsValid) + { + _context.Add(order); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + return View(order); + } + + // GET: Admin/Orders/Edit/5 + public async Task Edit(int? id) + { + if (id == null) + { + return NotFound(); + } + + var order = await _context.Order.FindAsync(id); + if (order == null) + { + return NotFound(); + } + return View(order); + } + + // POST: Admin/Orders/Edit/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("Order_Number,id,Created,Updated")] Order order) + { + if (id != order.id) + { + return NotFound(); + } + + if (ModelState.IsValid) + { + try + { + _context.Update(order); + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!OrderExists(order.id)) + { + return NotFound(); + } + else + { + throw; + } + } + return RedirectToAction(nameof(Index)); + } + return View(order); + } + + // GET: Admin/Orders/Delete/5 + public async Task Delete(int? id) + { + if (id == null) + { + return NotFound(); + } + + var order = await _context.Order + .FirstOrDefaultAsync(m => m.id == id); + if (order == null) + { + return NotFound(); + } + + return View(order); + } + + // POST: Admin/Orders/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + var order = await _context.Order.FindAsync(id); + _context.Order.Remove(order); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + private bool OrderExists(int id) + { + return _context.Order.Any(e => e.id == id); + } + } +} diff --git a/Areas/Admin/Views/OrderItem/Create.cshtml b/Areas/Admin/Views/OrderItem/Create.cshtml new file mode 100644 index 0000000..cca69a2 --- /dev/null +++ b/Areas/Admin/Views/OrderItem/Create.cshtml @@ -0,0 +1,42 @@ +@model pwt_0x01_ng.Models.OrderItem + +@{ + ViewData["Title"] = "Create"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

OrderItem

+
+
+
+
+
+
+ + +
+
+ + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + diff --git a/Areas/Admin/Views/OrderItem/Delete.cshtml b/Areas/Admin/Views/OrderItem/Delete.cshtml new file mode 100644 index 0000000..c904c30 --- /dev/null +++ b/Areas/Admin/Views/OrderItem/Delete.cshtml @@ -0,0 +1,57 @@ +@model pwt_0x01_ng.Models.OrderItem + +@{ + ViewData["Title"] = "Delete"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Are you sure you want to delete this?

+
+

OrderItem

+
+
+
+ @Html.DisplayNameFor(model => model.Amount) +
+
+ @Html.DisplayFor(model => model.Amount) +
+
+ @Html.DisplayNameFor(model => model.Price) +
+
+ @Html.DisplayFor(model => model.Price) +
+
+ @Html.DisplayNameFor(model => model.Order) +
+
+ @Html.DisplayFor(model => model.Order.Order_Number) +
+
+ @Html.DisplayNameFor(model => model.Product) +
+
+ @Html.DisplayFor(model => model.Product.Description) +
+
+ @Html.DisplayNameFor(model => model.Created) +
+
+ @Html.DisplayFor(model => model.Created) +
+
+ @Html.DisplayNameFor(model => model.Updated) +
+
+ @Html.DisplayFor(model => model.Updated) +
+
+ +
+ + | + Back to List +
+
diff --git a/Areas/Admin/Views/OrderItem/Details.cshtml b/Areas/Admin/Views/OrderItem/Details.cshtml new file mode 100644 index 0000000..37b1672 --- /dev/null +++ b/Areas/Admin/Views/OrderItem/Details.cshtml @@ -0,0 +1,54 @@ +@model pwt_0x01_ng.Models.OrderItem + +@{ + ViewData["Title"] = "Details"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +
+

OrderItem

+
+
+
+ @Html.DisplayNameFor(model => model.Amount) +
+
+ @Html.DisplayFor(model => model.Amount) +
+
+ @Html.DisplayNameFor(model => model.Price) +
+
+ @Html.DisplayFor(model => model.Price) +
+
+ @Html.DisplayNameFor(model => model.Order) +
+
+ @Html.DisplayFor(model => model.Order.Order_Number) +
+
+ @Html.DisplayNameFor(model => model.Product) +
+
+ @Html.DisplayFor(model => model.Product.Description) +
+
+ @Html.DisplayNameFor(model => model.Created) +
+
+ @Html.DisplayFor(model => model.Created) +
+
+ @Html.DisplayNameFor(model => model.Updated) +
+
+ @Html.DisplayFor(model => model.Updated) +
+
+
+ diff --git a/Areas/Admin/Views/OrderItem/Edit.cshtml b/Areas/Admin/Views/OrderItem/Edit.cshtml new file mode 100644 index 0000000..9315983 --- /dev/null +++ b/Areas/Admin/Views/OrderItem/Edit.cshtml @@ -0,0 +1,55 @@ +@model pwt_0x01_ng.Models.OrderItem + +@{ + ViewData["Title"] = "Edit"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

OrderItem

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+ +
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + diff --git a/Areas/Admin/Views/OrderItem/Index.cshtml b/Areas/Admin/Views/OrderItem/Index.cshtml new file mode 100644 index 0000000..99f14c8 --- /dev/null +++ b/Areas/Admin/Views/OrderItem/Index.cshtml @@ -0,0 +1,65 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "OrderItem"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

+ Create New +

+ + + + + + + + + + + + + +@foreach (var item in Model) { + + + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.Amount) + + @Html.DisplayNameFor(model => model.Price) + + @Html.DisplayNameFor(model => model.Order) + + @Html.DisplayNameFor(model => model.Product) + + @Html.DisplayNameFor(model => model.Created) + + @Html.DisplayNameFor(model => model.Updated) +
+ @Html.DisplayFor(modelItem => item.Amount) + + @Html.DisplayFor(modelItem => item.Price) + + @Html.DisplayFor(modelItem => item.Order.Order_Number) + + @Html.DisplayFor(modelItem => item.Product.Description) + + @Html.DisplayFor(modelItem => item.Created) + + @Html.DisplayFor(modelItem => item.Updated) + + Edit | + Details | + Delete +
diff --git a/Areas/Admin/Views/Orders/Create.cshtml b/Areas/Admin/Views/Orders/Create.cshtml new file mode 100644 index 0000000..0f1b543 --- /dev/null +++ b/Areas/Admin/Views/Orders/Create.cshtml @@ -0,0 +1,29 @@ +@model pwt_0x01_ng.Models.Order + +@{ + ViewData["Title"] = "Create"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Order

+
+
+
+
+
+
+ + + +
+
+ +
+
+
+
+ + diff --git a/Areas/Admin/Views/Orders/Delete.cshtml b/Areas/Admin/Views/Orders/Delete.cshtml new file mode 100644 index 0000000..a565b39 --- /dev/null +++ b/Areas/Admin/Views/Orders/Delete.cshtml @@ -0,0 +1,39 @@ +@model pwt_0x01_ng.Models.Order + +@{ + ViewData["Title"] = "Delete"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Are you sure you want to delete this?

+
+

Order

+
+
+
+ @Html.DisplayNameFor(model => model.Order_Number) +
+
+ @Html.DisplayFor(model => model.Order_Number) +
+
+ @Html.DisplayNameFor(model => model.Created) +
+
+ @Html.DisplayFor(model => model.Created) +
+
+ @Html.DisplayNameFor(model => model.Updated) +
+
+ @Html.DisplayFor(model => model.Updated) +
+
+ +
+ + | + Back to List +
+
diff --git a/Areas/Admin/Views/Orders/Details.cshtml b/Areas/Admin/Views/Orders/Details.cshtml new file mode 100644 index 0000000..a027a1b --- /dev/null +++ b/Areas/Admin/Views/Orders/Details.cshtml @@ -0,0 +1,36 @@ +@model pwt_0x01_ng.Models.Order + +@{ + ViewData["Title"] = "Details"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +
+

Order

+
+
+
+ @Html.DisplayNameFor(model => model.Order_Number) +
+
+ @Html.DisplayFor(model => model.Order_Number) +
+
+ @Html.DisplayNameFor(model => model.Created) +
+
+ @Html.DisplayFor(model => model.Created) +
+
+ @Html.DisplayNameFor(model => model.Updated) +
+
+ @Html.DisplayFor(model => model.Updated) +
+
+
+ diff --git a/Areas/Admin/Views/Orders/Edit.cshtml b/Areas/Admin/Views/Orders/Edit.cshtml new file mode 100644 index 0000000..33d064a --- /dev/null +++ b/Areas/Admin/Views/Orders/Edit.cshtml @@ -0,0 +1,40 @@ +@model pwt_0x01_ng.Models.Order + +@{ + ViewData["Title"] = "Edit"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Order

+
+
+
+
+
+
+ + + +
+ +
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + diff --git a/Areas/Admin/Views/Orders/Index.cshtml b/Areas/Admin/Views/Orders/Index.cshtml new file mode 100644 index 0000000..4e4e11a --- /dev/null +++ b/Areas/Admin/Views/Orders/Index.cshtml @@ -0,0 +1,46 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+

+ Create New +

+ + + + + + + + + + +@foreach (var item in Model) { + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.Order_Number) + + @Html.DisplayNameFor(model => model.Created) + + @Html.DisplayNameFor(model => model.Updated) +
+ @Html.DisplayFor(modelItem => item.Order_Number) + + @Html.DisplayFor(modelItem => item.Created) + + @Html.DisplayFor(modelItem => item.Updated) + + Edit | + Details | + Delete +
diff --git a/Makefile b/Makefile index de90dd9..382070a 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,16 @@ dargskaniko = -w=$(wdir) -v $$(pwd):$(wdir) $(kanikoimg) kanikoargs = -c=$(wdir) --use-new-run --snapshotMode=redo --no-push krelease = $(dcmdrun) $(dargskaniko) -f=$(dfile) $(kanikoargs) kdebug = $(dcmdrun) $(dargskaniko) -f=$(dfiledev) $(kanikoargs) +pgdbcapdrop = --cap-drop NET_ADMIN --cap-drop SYS_ADMIN +pgdbenv = -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266 -e POSTGRES_INITDB_ARGS="--data-checksums" +pgdbname = pgdb +pgdbports = -p 127.0.0.1:5433:5432 +pgdbvol = -v pgdbdata:/var/lib/postgresql/data +pgdbargs = run -d $(pgdbcapdrop) $(pgdbenv) --name $(pgdbname) $(pgdbports) $(pgdbvol) --restart unless-stopped +pgdbimg = postgres:13.1-alpine +zenv = DB_CONNECTION_STRING=$$(cat appsettings.Development.json | jq .db.Postgres | sed -e 's/5432/5433/' -e 's/=db/=localhost/' -e 's/"//g') -.PHONY: dev dockerbuild dockerdevbuild dockerrun dockerdevrun dockertest dockerdev kaniko clean prune test +.PHONY: dev dockerbuild dockerdevbuild dockerrun dockerdevrun dockertest dockerdev kaniko clean prune pgdba pgdbz test dev: restore build run @@ -26,7 +34,7 @@ build: $(CC) build . run: - $(CC) run . + $(zenv) $(CC) watch run . releasebuild: restore clean $(CC) publish -c Release @@ -76,3 +84,9 @@ clean: prune: $(dcmd) $(pruneargs) + +pgdba: + $(dcmd) $(pgdbargs) $(pgdbimg) + +pgdbz: + $(dcmd) stop $(pgdbname) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 2af179e..621e0bc 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -46,6 +46,12 @@
  • Products
  • +
  • + Orders +
  • +
  • + OrderItems +
  • diff --git a/pwt-0x01-ng.csproj b/pwt-0x01-ng.csproj index a4dea24..439d273 100644 --- a/pwt-0x01-ng.csproj +++ b/pwt-0x01-ng.csproj @@ -15,6 +15,8 @@ + + @@ -22,6 +24,7 @@ +