From 9383a2fb09ffb60cfe63683106945bd688affa59 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 1 Jun 2022 21:13:43 +0200 Subject: feat: Initial commit after clean slate --- src/Pages/Errors/Index.cshtml | 33 +++++ src/Pages/Errors/Index.cshtml.cs | 19 +++ src/Pages/Handlekorg.cshtml | 100 +++++++++++++++ src/Pages/Handlekorg.cshtml.cs | 8 ++ src/Pages/Index.cshtml | 41 ++++++ src/Pages/Index.cshtml.cs | 34 +++++ src/Pages/Kontoret/Bestillinger.cshtml | 67 ++++++++++ src/Pages/Kontoret/Bestillinger.cshtml.cs | 8 ++ src/Pages/Kontoret/Dokumenter.cshtml | 21 +++ src/Pages/Kontoret/Dokumenter.cshtml.cs | 8 ++ src/Pages/Kontoret/Produkter.cshtml | 18 +++ src/Pages/Kontoret/Produkter.cshtml.cs | 8 ++ src/Pages/Kontoret/_ViewImports.cshtml | 3 + src/Pages/Kontoret/_ViewStart.cshtml | 3 + src/Pages/Leverandorar.cshtml | 9 ++ src/Pages/Leverandorar.cshtml.cs | 23 ++++ src/Pages/LoggInn.cshtml | 34 +++++ src/Pages/LoggInn.cshtml.cs | 19 +++ src/Pages/OmOss.cshtml | 9 ++ src/Pages/OmOss.cshtml.cs | 23 ++++ src/Pages/Partials/_AdminCategoriesModal.cshtml | 25 ++++ src/Pages/Partials/_AdminProductModal.cshtml | 72 +++++++++++ src/Pages/Partials/_CultureSelector.cshtml | 35 +++++ src/Pages/Personvern.cshtml | 8 ++ src/Pages/Personvern.cshtml.cs | 25 ++++ src/Pages/Produktar.cshtml | 163 ++++++++++++++++++++++++ src/Pages/Produktar.cshtml.cs | 82 ++++++++++++ src/Pages/SalesTerms.cshtml | 9 ++ src/Pages/SalesTerms.cshtml.cs | 25 ++++ src/Pages/Shared/_AdminLayout.cshtml | 114 +++++++++++++++++ src/Pages/Shared/_PublicLayout.cshtml | 152 ++++++++++++++++++++++ src/Pages/Status.cshtml | 136 ++++++++++++++++++++ src/Pages/Status.cshtml.cs | 53 ++++++++ src/Pages/_ViewImports.cshtml | 3 + src/Pages/_ViewStart.cshtml | 3 + 35 files changed, 1393 insertions(+) create mode 100644 src/Pages/Errors/Index.cshtml create mode 100644 src/Pages/Errors/Index.cshtml.cs create mode 100644 src/Pages/Handlekorg.cshtml create mode 100644 src/Pages/Handlekorg.cshtml.cs create mode 100644 src/Pages/Index.cshtml create mode 100644 src/Pages/Index.cshtml.cs create mode 100644 src/Pages/Kontoret/Bestillinger.cshtml create mode 100644 src/Pages/Kontoret/Bestillinger.cshtml.cs create mode 100644 src/Pages/Kontoret/Dokumenter.cshtml create mode 100644 src/Pages/Kontoret/Dokumenter.cshtml.cs create mode 100644 src/Pages/Kontoret/Produkter.cshtml create mode 100644 src/Pages/Kontoret/Produkter.cshtml.cs create mode 100644 src/Pages/Kontoret/_ViewImports.cshtml create mode 100644 src/Pages/Kontoret/_ViewStart.cshtml create mode 100644 src/Pages/Leverandorar.cshtml create mode 100644 src/Pages/Leverandorar.cshtml.cs create mode 100644 src/Pages/LoggInn.cshtml create mode 100644 src/Pages/LoggInn.cshtml.cs create mode 100644 src/Pages/OmOss.cshtml create mode 100644 src/Pages/OmOss.cshtml.cs create mode 100644 src/Pages/Partials/_AdminCategoriesModal.cshtml create mode 100644 src/Pages/Partials/_AdminProductModal.cshtml create mode 100644 src/Pages/Partials/_CultureSelector.cshtml create mode 100644 src/Pages/Personvern.cshtml create mode 100644 src/Pages/Personvern.cshtml.cs create mode 100644 src/Pages/Produktar.cshtml create mode 100644 src/Pages/Produktar.cshtml.cs create mode 100644 src/Pages/SalesTerms.cshtml create mode 100644 src/Pages/SalesTerms.cshtml.cs create mode 100644 src/Pages/Shared/_AdminLayout.cshtml create mode 100644 src/Pages/Shared/_PublicLayout.cshtml create mode 100644 src/Pages/Status.cshtml create mode 100644 src/Pages/Status.cshtml.cs create mode 100644 src/Pages/_ViewImports.cshtml create mode 100644 src/Pages/_ViewStart.cshtml (limited to 'src/Pages') diff --git a/src/Pages/Errors/Index.cshtml b/src/Pages/Errors/Index.cshtml new file mode 100644 index 0000000..5db7b59 --- /dev/null +++ b/src/Pages/Errors/Index.cshtml @@ -0,0 +1,33 @@ +@page "{code}" +@using System.Net +@model VSH.Pages.Errors.Index +@{ + ViewData["Title"] = Model.ErrorStatusCode switch { + HttpStatusCode.NotFound => "Fant ikkje sida", + var _ => "Uventa feil" + }; +} +
+ @switch (Model.ErrorStatusCode) { + case HttpStatusCode.NotFound: +
+

Fant ikkje siden

+

Beklagar, sida du prøvar å nå finnes ikkje.

+

Gå til forsida eller kontakt oss.

+
+ break; + case HttpStatusCode.InternalServerError: +
+

Her gjekk noko gale

+

Vi jobbar med å løysa problemet, ver vennleg og prøv igjen seinare.

+
+ break; + default: +
+

Heisann, her gjekk ikkje alt etter planen

+

Ver vennleg og prøv igjen snart.

+

Gå til forsida eller kontakt oss.

+
+ break; + } +
diff --git a/src/Pages/Errors/Index.cshtml.cs b/src/Pages/Errors/Index.cshtml.cs new file mode 100644 index 0000000..05e405d --- /dev/null +++ b/src/Pages/Errors/Index.cshtml.cs @@ -0,0 +1,19 @@ +using System; +using System.Net; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VSH.Pages.Errors; + +public class Index : PageModel +{ + public HttpStatusCode ErrorStatusCode { get; set; } + + public void OnGet() { + try { + if (int.TryParse(RouteData.Values["code"]?.ToString(), out var status)) + ErrorStatusCode = (HttpStatusCode)status; + } catch (Exception e) { + Console.WriteLine(e); + } + } +} \ No newline at end of file diff --git a/src/Pages/Handlekorg.cshtml b/src/Pages/Handlekorg.cshtml new file mode 100644 index 0000000..9f8f159 --- /dev/null +++ b/src/Pages/Handlekorg.cshtml @@ -0,0 +1,100 @@ +@page +@model VSH.Pages.Handlekorg +@{ + ViewData["Title"] = "Handlekorg"; +} + +
+
+
+
+
+ Lastar... +
+
+
+ + + + + + + + + + +
ProduktAntallPrisTotalsum
+
+
+
+ Totalt inkl. MVA: + Av dei MVA: +
+
+
+
+
+
+
+
+ Lastar... +
+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
    +
    + Betal med + +
    +
    +

    Gå til vipps for å fullføre betalinga

    +
    + + +
    +
    + +
    +
    +
    +

    Du får tilsendt faktura på mail til e-postadressa di

    +
    + + +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/src/Pages/Handlekorg.cshtml.cs b/src/Pages/Handlekorg.cshtml.cs new file mode 100644 index 0000000..02f72a7 --- /dev/null +++ b/src/Pages/Handlekorg.cshtml.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VSH.Pages; + +public class Handlekorg : PageModel +{ + public void OnGet() { } +} \ No newline at end of file diff --git a/src/Pages/Index.cshtml b/src/Pages/Index.cshtml new file mode 100644 index 0000000..aa23602 --- /dev/null +++ b/src/Pages/Index.cshtml @@ -0,0 +1,41 @@ +@page +@using Microsoft.Extensions.Localization +@inject IStringLocalizer Localizer; +@model IndexModel +@{ + ViewData["Title"] = Localizer["Forsida"]; +} + +@section Head { + +} + +
    + + + + + +
    +
    +
    + @if (Model.HighlightedProducts.Any(c => c.IsAvailable && c.IsVisible)) { +

    Favorittar

    +
    + @foreach (var product in Model.HighlightedProducts.Where(c => c.IsVisible && c.IsAvailable).OrderByDescending(c => c.Updated)) { + + ... +

    @product.Name

    +
    + } +
    + } +
    +
    + @Html.Raw(Model.ContactHtml) +
    +
    \ No newline at end of file diff --git a/src/Pages/Index.cshtml.cs b/src/Pages/Index.cshtml.cs new file mode 100644 index 0000000..3cefa0d --- /dev/null +++ b/src/Pages/Index.cshtml.cs @@ -0,0 +1,34 @@ +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; +using VSH.Data.Enums; + +namespace VSH.Pages; + +public class IndexModel : PageModel +{ + private readonly MainDbContext _context; + + public string ContactHtml { get; set; } + public List HighlightedProducts { get; set; } = new(); + + public IndexModel(MainDbContext context) { + _context = context; + } + + public ActionResult OnGet() { + ContactHtml = _context.Documents.OrderBy(c => c.Created) + .LastOrDefault(c => c.Type == DocumentType.CONTACT_PAGE) + ?.Content; + HighlightedProducts = _context.Products + .Where(c => c.ShowOnFrontpage + && c.VisibilityState == ProductVisibility.DEFAULT) + .Include(c => c.Category) + .ToList(); + return Page(); + } +} \ No newline at end of file diff --git a/src/Pages/Kontoret/Bestillinger.cshtml b/src/Pages/Kontoret/Bestillinger.cshtml new file mode 100644 index 0000000..961e12a --- /dev/null +++ b/src/Pages/Kontoret/Bestillinger.cshtml @@ -0,0 +1,67 @@ +@page +@model VSH.Pages.Kontoret.Bestillinger +@{ + ViewData["Title"] = "Bestillinger"; +} +
    +
    + Laster... +
    +
    +
    + + \ No newline at end of file diff --git a/src/Pages/Kontoret/Bestillinger.cshtml.cs b/src/Pages/Kontoret/Bestillinger.cshtml.cs new file mode 100644 index 0000000..8aff3c4 --- /dev/null +++ b/src/Pages/Kontoret/Bestillinger.cshtml.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VSH.Pages.Kontoret; + +public class Bestillinger : PageModel +{ + public void OnGet() { } +} \ No newline at end of file diff --git a/src/Pages/Kontoret/Dokumenter.cshtml b/src/Pages/Kontoret/Dokumenter.cshtml new file mode 100644 index 0000000..55e0ba6 --- /dev/null +++ b/src/Pages/Kontoret/Dokumenter.cshtml @@ -0,0 +1,21 @@ +@page +@using VSH.Data.Enums +@using VSH.Utilities +@using IOL.Helpers +@model VSH.Pages.Kontoret.Dokumenter +@{ + ViewData["Title"] = "Dokumenter"; +} + +
    + + +
    + +
    \ No newline at end of file diff --git a/src/Pages/Kontoret/Dokumenter.cshtml.cs b/src/Pages/Kontoret/Dokumenter.cshtml.cs new file mode 100644 index 0000000..ca72b4e --- /dev/null +++ b/src/Pages/Kontoret/Dokumenter.cshtml.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VSH.Pages.Kontoret; + +public class Dokumenter : PageModel +{ + public void OnGet() { } +} \ No newline at end of file diff --git a/src/Pages/Kontoret/Produkter.cshtml b/src/Pages/Kontoret/Produkter.cshtml new file mode 100644 index 0000000..825005d --- /dev/null +++ b/src/Pages/Kontoret/Produkter.cshtml @@ -0,0 +1,18 @@ +@page +@model VSH.Pages.Kontoret.Produkter2 +@{ + ViewData["Title"] = "Produkter"; +} + + + + +
    +
    + Laster... +
    +
    +
    + + + \ No newline at end of file diff --git a/src/Pages/Kontoret/Produkter.cshtml.cs b/src/Pages/Kontoret/Produkter.cshtml.cs new file mode 100644 index 0000000..0d16e08 --- /dev/null +++ b/src/Pages/Kontoret/Produkter.cshtml.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VSH.Pages.Kontoret; + +public class Produkter2 : PageModel +{ + public void OnGet() { } +} \ No newline at end of file diff --git a/src/Pages/Kontoret/_ViewImports.cshtml b/src/Pages/Kontoret/_ViewImports.cshtml new file mode 100644 index 0000000..01f3f6a --- /dev/null +++ b/src/Pages/Kontoret/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@using VSH +@namespace VSH.Pages.Kontoret +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/src/Pages/Kontoret/_ViewStart.cshtml b/src/Pages/Kontoret/_ViewStart.cshtml new file mode 100644 index 0000000..0297c66 --- /dev/null +++ b/src/Pages/Kontoret/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_AdminLayout"; +} \ No newline at end of file diff --git a/src/Pages/Leverandorar.cshtml b/src/Pages/Leverandorar.cshtml new file mode 100644 index 0000000..eb712a5 --- /dev/null +++ b/src/Pages/Leverandorar.cshtml @@ -0,0 +1,9 @@ +@page "/leverandørar" +@model VSH.Pages.Leverandorar +@{ + ViewData["Title"] = "Leverandørar"; +} + +
    + @Html.Raw(Model.DealersPageHtml) +
    \ No newline at end of file diff --git a/src/Pages/Leverandorar.cshtml.cs b/src/Pages/Leverandorar.cshtml.cs new file mode 100644 index 0000000..e8f467b --- /dev/null +++ b/src/Pages/Leverandorar.cshtml.cs @@ -0,0 +1,23 @@ +using System.Linq; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using VSH.Data; +using VSH.Data.Enums; + +namespace VSH.Pages; + +public class Leverandorar : PageModel +{ + private readonly MainDbContext _context; + + public Leverandorar(MainDbContext context) { + context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + _context = context; + } + + public string DealersPageHtml { get; set; } + + public void OnGet() { + DealersPageHtml = _context.Documents.FirstOrDefault(c => c.Type == DocumentType.DEALERS_PAGE)?.Content; + } +} \ No newline at end of file diff --git a/src/Pages/LoggInn.cshtml b/src/Pages/LoggInn.cshtml new file mode 100644 index 0000000..6349466 --- /dev/null +++ b/src/Pages/LoggInn.cshtml @@ -0,0 +1,34 @@ +@page +@using Microsoft.AspNetCore.Antiforgery +@model VSH.Pages.LoggInn +@inject IAntiforgery Antiforgery +@{ + ViewData["Title"] = "Logg inn"; + var token = Antiforgery.GetAndStoreTokens(HttpContext).RequestToken; +} + +
    + +
    +
    + + +
    +
    + + +
    +
    + + +
    + + +
    +
    diff --git a/src/Pages/LoggInn.cshtml.cs b/src/Pages/LoggInn.cshtml.cs new file mode 100644 index 0000000..d4ee7d7 --- /dev/null +++ b/src/Pages/LoggInn.cshtml.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VSH.Pages; + +public class LoggInn : PageModel +{ + public ActionResult OnGet() { + if (User.Identity?.IsAuthenticated ?? false) { + if (Request.Query.ContainsKey("ReturnUrl")) { + return Redirect(Request.Query["ReturnUrl"]); + } + + return Redirect("/kontoret"); + } + + return Page(); + } +} \ No newline at end of file diff --git a/src/Pages/OmOss.cshtml b/src/Pages/OmOss.cshtml new file mode 100644 index 0000000..0ba277c --- /dev/null +++ b/src/Pages/OmOss.cshtml @@ -0,0 +1,9 @@ +@page "/om-oss" +@model VSH.Pages.OmOss +@{ + ViewData["Title"] = "Om oss"; +} + +
    + @Html.Raw(Model.AboutUsPageHtml) +
    \ No newline at end of file diff --git a/src/Pages/OmOss.cshtml.cs b/src/Pages/OmOss.cshtml.cs new file mode 100644 index 0000000..217f829 --- /dev/null +++ b/src/Pages/OmOss.cshtml.cs @@ -0,0 +1,23 @@ +using System.Linq; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using VSH.Data; +using VSH.Data.Enums; + +namespace VSH.Pages; + +public class OmOss : PageModel +{ + private readonly MainDbContext _context; + + public OmOss(MainDbContext context) { + context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + _context = context; + } + + public string AboutUsPageHtml { get; set; } + + public void OnGet() { + AboutUsPageHtml = _context.Documents.FirstOrDefault(c => c.Type == DocumentType.ABOUT_PAGE)?.Content; + } +} \ No newline at end of file diff --git a/src/Pages/Partials/_AdminCategoriesModal.cshtml b/src/Pages/Partials/_AdminCategoriesModal.cshtml new file mode 100644 index 0000000..ee52f2a --- /dev/null +++ b/src/Pages/Partials/_AdminCategoriesModal.cshtml @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/src/Pages/Partials/_AdminProductModal.cshtml b/src/Pages/Partials/_AdminProductModal.cshtml new file mode 100644 index 0000000..06cbc81 --- /dev/null +++ b/src/Pages/Partials/_AdminProductModal.cshtml @@ -0,0 +1,72 @@ + \ No newline at end of file diff --git a/src/Pages/Partials/_CultureSelector.cshtml b/src/Pages/Partials/_CultureSelector.cshtml new file mode 100644 index 0000000..07965f9 --- /dev/null +++ b/src/Pages/Partials/_CultureSelector.cshtml @@ -0,0 +1,35 @@ +@using Microsoft.AspNetCore.Builder +@using Microsoft.AspNetCore.Localization +@using Microsoft.Extensions.Localization +@using Microsoft.Extensions.Options +@using IOL.Helpers + +@inject IStringLocalizer Localizer +@inject IOptions LocOptions + +@{ + var requestCulture = Context.Features.Get(); + var cultureItems = LocOptions.Value.SupportedUICultures; +} + +
    +
    +
    + +
    + +
    +
    \ No newline at end of file diff --git a/src/Pages/Personvern.cshtml b/src/Pages/Personvern.cshtml new file mode 100644 index 0000000..83d5043 --- /dev/null +++ b/src/Pages/Personvern.cshtml @@ -0,0 +1,8 @@ +@page +@model PrivacyModel +@{ + ViewData["Title"] = "Personvern"; +} +
    + @Html.Raw(Model.PrivacyPolicyHtml) +
    \ No newline at end of file diff --git a/src/Pages/Personvern.cshtml.cs b/src/Pages/Personvern.cshtml.cs new file mode 100644 index 0000000..1a661c5 --- /dev/null +++ b/src/Pages/Personvern.cshtml.cs @@ -0,0 +1,25 @@ +using System.Linq; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using VSH.Data; +using VSH.Data.Enums; + +namespace VSH.Pages; + +public class PrivacyModel : PageModel +{ + private readonly MainDbContext _context; + + public PrivacyModel(MainDbContext context) { + context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + _context = context; + } + + public string PrivacyPolicyHtml { get; set; } + + public void OnGet() { + PrivacyPolicyHtml = _context.Documents.OrderBy(c => c.Created) + .LastOrDefault(c => c.Type == DocumentType.PRIVACY_POLICY) + ?.Content; + } +} \ No newline at end of file diff --git a/src/Pages/Produktar.cshtml b/src/Pages/Produktar.cshtml new file mode 100644 index 0000000..f43e4ab --- /dev/null +++ b/src/Pages/Produktar.cshtml @@ -0,0 +1,163 @@ +@page "{categorySlug?}/{productSlug?}" +@using VSH.Data.Static +@using IOL.Helpers +@model VSH.Pages.Produktar +@{ + var title = "Produktar"; + if (Model.IsProduct) { + title = Model.CurrentProduct.Name; + } else if (Model.IsCategory) { + title = Model.Categories.FirstOrDefault()?.Name; + } + + ViewData["Title"] = title; +} + +
    + @if (Model.IsCategory || Model.IsProduct) { + + } + + @if (Model.IsProduct) { +
    +
    + @if (Model.CurrentProduct.Images.Any()) { + if (Model.CurrentProduct.Images.Count > 1) { + + + } else { + var fileName = Model.CurrentProduct.GetPrimaryImage(); + Bilde av produktet + } + } else { + Bilde av produktet + } +
    +
    +
    +

    @Model.CurrentProduct.Name

    +

    @Model.CurrentProduct.Description

    +
    +
    +
    + @if (Model.CurrentProduct.IsAvailable) { +
    +
    + + @Model.CurrentProduct.Price@(Model.CurrentProduct.ReadablePriceSuffix) +
    + } else { + + } +
    +
    +
    +
    + } else if ((Model.IsCategory || Model.IsCategories) && Model.Categories?.Count >= 1) { + foreach (var category in Model.Categories.Where(category => category.Products.Count >= 1)) { +
    +

    @category.Name

    + @foreach (var product in category.Products.Where(c => c.IsVisible)) { +
    +
    + @if (product.Images.Any()) { + var fileName = product.GetPrimaryImage(); + + + + } else { + + + + } +
    + + @product.Name + +
    + @if (product.IsAvailable) { +
    +
    + + @product.Price@(product.ReadablePriceSuffix) +
    + } else { + + } +
    +
    +
    +
    + } +
    + } + } else { +

    + Heisann, her er det tomt for augneblinken. Prøv igjen snart. +

    + } +
    \ No newline at end of file diff --git a/src/Pages/Produktar.cshtml.cs b/src/Pages/Produktar.cshtml.cs new file mode 100644 index 0000000..b0ba470 --- /dev/null +++ b/src/Pages/Produktar.cshtml.cs @@ -0,0 +1,82 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using IOL.Helpers; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; +using VSH.Data.Miscellaneous; +using VSH.Data.Database; +using VSH.Data; +using VSH.Data.Enums; +using VSH.Data.Static; + +namespace VSH.Pages; + +public class Produktar : PageModel +{ + private readonly MainDbContext _context; + private readonly IStringLocalizer _localizer; + private readonly IOptions _options; + + public string ProductSlug { get; set; } + public string CategorySlug { get; set; } + public bool IsProduct { get; set; } + public bool IsCategory { get; set; } + public bool IsCategories { get; set; } + public Product CurrentProduct { get; set; } + + public Produktar( + MainDbContext context, + IStringLocalizer localizer, + IOptions options + ) { + _context = context; + _localizer = localizer; + _options = options; + } + + public List Categories { get; set; } + + public ActionResult OnGet(string categorySlug, string productSlug) { + ProductSlug = productSlug; + CategorySlug = categorySlug; + + if (ProductSlug.HasValue()) { + CurrentProduct = _context.Products.Where(c => c.VisibilityState == ProductVisibility.DEFAULT) + .Include(c => c.Category) + .SingleOrDefault(p => p.Slug == ProductSlug); + IsProduct = CurrentProduct != default; + if (!IsProduct) + return Page(); + var productImage = CurrentProduct != null && CurrentProduct.Images.Any() + ? CurrentProduct.Images.OrderBy(c => c.Order).FirstOrDefault() + : default; + + ViewData["open_graph"] = new OpenGraphData { + Description = CurrentProduct?.Description, + Image = productImage != default + ? (HttpContext.Request.GetRequestHost() + + Path.Combine(AppPaths.ProductImages.WebPath, productImage.FileName)) + : default, + Title = $"{CurrentProduct?.Name} {_localizer["frå"]} {_options.Value.StoreName}", + }; + } else if (CategorySlug.HasValue()) { + Categories = _context + .Categories.Where(c => c.Slug == CategorySlug + && c.VisibilityState == CategoryVisibility.DEFAULT) + .Include(c => c.Products) + .ToList(); + IsCategory = !IsProduct && Categories?.Count == 1; + } else { + Categories = _context.Categories.Where(c => c.VisibilityState == CategoryVisibility.DEFAULT) + .Include(c => c.Products) + .ToList(); + IsCategories = !IsProduct && Categories?.Count >= 1; + } + + return Page(); + } +} \ No newline at end of file diff --git a/src/Pages/SalesTerms.cshtml b/src/Pages/SalesTerms.cshtml new file mode 100644 index 0000000..7c48bff --- /dev/null +++ b/src/Pages/SalesTerms.cshtml @@ -0,0 +1,9 @@ +@page "/vilkår" +@model VSH.Pages.SalesTerms +@{ + ViewData["Title"] = "Salgsvilkår"; +} + +
    + @Html.Raw(Model.TermsPageHtml) +
    \ No newline at end of file diff --git a/src/Pages/SalesTerms.cshtml.cs b/src/Pages/SalesTerms.cshtml.cs new file mode 100644 index 0000000..fe58839 --- /dev/null +++ b/src/Pages/SalesTerms.cshtml.cs @@ -0,0 +1,25 @@ +using System.Linq; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using VSH.Data; +using VSH.Data.Enums; + +namespace VSH.Pages; + +public class SalesTerms : PageModel +{ + private readonly MainDbContext _context; + + public SalesTerms(MainDbContext context) { + context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + _context = context; + } + + public string TermsPageHtml { get; set; } + + public void OnGet() { + TermsPageHtml = _context.Documents.OrderBy(c => c.Created) + .LastOrDefault(c => c.Type == DocumentType.SALES_TERMS) + ?.Content; + } +} \ No newline at end of file diff --git a/src/Pages/Shared/_AdminLayout.cshtml b/src/Pages/Shared/_AdminLayout.cshtml new file mode 100644 index 0000000..d352928 --- /dev/null +++ b/src/Pages/Shared/_AdminLayout.cshtml @@ -0,0 +1,114 @@ +@using VSH.Data.Miscellaneous +@using Microsoft.Extensions.Options +@using Microsoft.Extensions.Configuration +@using VSH.Utilities +@inject IOptions Options; +@inject IConfiguration Configuration; + + + + + + + + @await RenderSectionAsync("Head", required: false) + @ViewData["Title"] - Kontoret - @Options.Value.StoreName + + + +
    +
    +
    +
    +
    +

    @Options.Value.ShortStoreName

    +
    + +
    +
    +
    +
    +
    + +
    +
    + + + +
    + @RenderBody() +
    +
    + + + +@Configuration.GetVersion() + + +@await RenderSectionAsync("Scripts", required: false) + + \ No newline at end of file diff --git a/src/Pages/Shared/_PublicLayout.cshtml b/src/Pages/Shared/_PublicLayout.cshtml new file mode 100644 index 0000000..d3280dd --- /dev/null +++ b/src/Pages/Shared/_PublicLayout.cshtml @@ -0,0 +1,152 @@ +@using VSH.Data.Miscellaneous +@using Microsoft.Extensions.Options +@using Microsoft.Extensions.Localization +@using IOL.Helpers +@inject IOptions Options; +@inject IStringLocalizer Localizer; +@{ + var host = Context.Request.GetRequestHost(); + var currentUrl = host + Context.Request.Path.Value; + const string CURRENT_CULTURE = "nn"; + var openGraphData = ViewData["open_graph"] as OpenGraphData; +} + + + + + + + + + + + + + + + + + + + + @await RenderSectionAsync("Head", required: false) + @ViewData["Title"] - @Options.Value.StoreName + + + + + +
    + + @RenderBody() + +
    + + + + + + +@await RenderSectionAsync("Scripts", required: false) + + + diff --git a/src/Pages/Status.cshtml b/src/Pages/Status.cshtml new file mode 100644 index 0000000..d0e2ad1 --- /dev/null +++ b/src/Pages/Status.cshtml @@ -0,0 +1,136 @@ +@page "{orderReference}" +@using VSH.Data.Enums +@using VSH.Utilities +@using System.Globalization +@using IOL.Helpers +@model VSH.Pages.Status + +@{ + string title; + if (Model.CurrentOrder == default) { + title = "Fant ikkje ordren"; + } else { + title = Model.CurrentOrder.Status switch { + OrderStatus.CANCELLED => "Kansellert bestilling", + OrderStatus.FAILED => "Feila bestilling", + OrderStatus.COMPLETED => "Fullført bestilling", + OrderStatus.AWAITING_INVOICE + or OrderStatus.AWAITING_VIPPS + or OrderStatus.IN_PROGRESS => "Ventar på betaling", + var _ => "Uventa feil" + }; + } + ViewData["Title"] = title; +} +
    + @if (Model.CurrentOrder != default) { +
    +
    +
    +

    Din bestilling

    +
    +

    + Status: + @(title) +

    +

    + Betalingsmetode: + @(EnumName.ForPaymentType(Model.CurrentOrder.PaymentType)) + @if (Model.CurrentOrder.PaymentType == OrderPaymentType.INVOICE_BY_EMAIL) { + Du får tilsendt faktura til din e-postadresse + } +

    +

    + Referanse: + @Model.CurrentOrder.OrderReference +

    +

    + Dato: + @Model.CurrentOrder.Created.ToOsloTimeZone().ToString("dd.MM.yyyy HH:mm", new CultureInfo("nb-NO")) +

    + + @if (!Model.CurrentOrder.Comment.IsNullOrWhiteSpace()) { +

    + Øvrig informasjon: + @Model.CurrentOrder.Comment +

    + } + +
    +
    +

    Kontaktinformasjon

    +
    +

    + Namn: + @Model.CurrentOrder.ContactInfo.Name +

    + + @if (!Model.CurrentOrder.ContactInfo.EmailAddress.IsNullOrWhiteSpace()) { +

    + E-postadresse: + @Model.CurrentOrder.ContactInfo.EmailAddress +

    + } + + @if (!Model.CurrentOrder.ContactInfo.PhoneNumber.IsNullOrWhiteSpace()) { +

    + Telefonnummer: + @Model.CurrentOrder.ContactInfo.PhoneNumber +

    + } +
    +
    +

    Spørsmål?

    +
    +

    Ta gjerne kontakt hvis du har spørsmål vedrørande ordren din.

    +
    +
    +
    +
    +

    Produktar

    +
    +
    + @foreach (var product in Model.CurrentOrderProducts) { +
    + + + +
    + @product.DbProdcut.Name +
    + Antall: @product.OrderProduct.NumberOfItems + + Totalt: + + @product.OrderProduct.Total().ToString("N", new NumberFormatInfo { + CurrencyDecimalDigits = 2 + }),- + + +
    +
    +
    + } +
    +
    +
    + + Totalt: @Model.CurrentOrder.Total().ToString("N", new NumberFormatInfo { + CurrencyDecimalDigits = 2 + }),- + + + Av dei MVA: @Model.CurrentOrder.Tax().ToString("N", new NumberFormatInfo { + CurrencyDecimalDigits = 2 + }),- + +
    +
    +
    +
    +
    + } else { +

    Vi fant ikkje din ordre

    +

    Ver vennleg og kontakt oss hvis du meiner dette er ein feil.

    + } +
    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 CurrentOrderProducts { get; } + + public Status(MainDbContext context) { + _context = context; + CurrentOrderProducts = new List(); + } + + 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 diff --git a/src/Pages/_ViewImports.cshtml b/src/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..3a327c4 --- /dev/null +++ b/src/Pages/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@using VSH +@namespace VSH.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/src/Pages/_ViewStart.cshtml b/src/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..45bfaa9 --- /dev/null +++ b/src/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_PublicLayout"; +} -- cgit v1.3