diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-06-01 21:13:43 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-06-01 21:13:43 +0200 |
| commit | 9383a2fb09ffb60cfe63683106945bd688affa59 (patch) | |
| tree | 65b3f4b48841583e355887db5de5a16e7005fc87 /src/Pages/Status.cshtml.cs | |
| download | vinjesvingenhandel.no-9383a2fb09ffb60cfe63683106945bd688affa59.tar.xz vinjesvingenhandel.no-9383a2fb09ffb60cfe63683106945bd688affa59.zip | |
feat: Initial commit after clean slate
Diffstat (limited to 'src/Pages/Status.cshtml.cs')
| -rw-r--r-- | src/Pages/Status.cshtml.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Pages/Status.cshtml.cs b/src/Pages/Status.cshtml.cs new file mode 100644 index 0000000..ed15120 --- /dev/null +++ b/src/Pages/Status.cshtml.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using VSH.Data; +using VSH.Data.Database; + +namespace VSH.Pages; + +public class Status : PageModel +{ + private readonly MainDbContext _context; + public Order CurrentOrder { get; private set; } + public List<StatusProduct> CurrentOrderProducts { get; } + + public Status(MainDbContext context) { + _context = context; + CurrentOrderProducts = new List<StatusProduct>(); + } + + public ActionResult OnGet(string orderReference) { + try { + CurrentOrder = _context.Orders.SingleOrDefault(o => o.OrderReference == orderReference); + if (CurrentOrder == default) return Page(); + + foreach (var orderProduct in CurrentOrder.Products) { + var dbProduct = _context.Products.Include(c => c.Category) + .SingleOrDefault(p => p.Id == orderProduct.Id); + if (dbProduct == default) continue; + CurrentOrderProducts.Add(new StatusProduct(dbProduct, orderProduct)); + } + + return Page(); + } catch (Exception e) { + Console.WriteLine(e); + } + + return Redirect("/errors/500"); + } + + public class StatusProduct + { + public StatusProduct(Product dbProdcut, OrderProduct orderProduct) { + DbProdcut = dbProdcut; + OrderProduct = orderProduct; + } + + public Product DbProdcut { get; } + public OrderProduct OrderProduct { get; } + } +}
\ No newline at end of file |
