From 0c2219ff665cbed5b9ae55bc08849c98d1c7b8f1 Mon Sep 17 00:00:00 2001 From: Laci <mlacko020523@gmail.com> Date: Tue, 5 Mar 2024 18:06:08 +0100 Subject: [PATCH] submit and Submissions pages --- Rendelosch/Pages/Index.cshtml | 2 +- Rendelosch/Pages/SubmissionsPage.cshtml | 39 ++++++++++++++++++++++ Rendelosch/Pages/SubmissionsPage.cshtml.cs | 20 +++++++++++ Rendelosch/Pages/SubmitForm.cshtml | 7 ++-- Rendelosch/Pages/SubmitForm.cshtml.cs | 18 ++++++++-- 5 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 Rendelosch/Pages/SubmissionsPage.cshtml create mode 100644 Rendelosch/Pages/SubmissionsPage.cshtml.cs diff --git a/Rendelosch/Pages/Index.cshtml b/Rendelosch/Pages/Index.cshtml index 01e97a7..5f953a6 100644 --- a/Rendelosch/Pages/Index.cshtml +++ b/Rendelosch/Pages/Index.cshtml @@ -16,7 +16,7 @@ <a asp-page="SubmitForm" asp-route-id="@productForm.Id"> <h5 class="card-title m-0 me-3">@productForm.Title</h5> </a> - <a class="btn btn-outline-primary mx-1" asp-page="SubmittedForms" asp-route-id="@productForm.Id">Submissions</a> + <a class="btn btn-outline-primary mx-1" asp-page="SubmissionsPage" asp-route-id="@productForm.Id">Submissions</a> </div> </div> </div> diff --git a/Rendelosch/Pages/SubmissionsPage.cshtml b/Rendelosch/Pages/SubmissionsPage.cshtml new file mode 100644 index 0000000..b3864a4 --- /dev/null +++ b/Rendelosch/Pages/SubmissionsPage.cshtml @@ -0,0 +1,39 @@ +@page "{Id}" +@model Rendelosch.Pages.Shared.SubmissionsPage + +@{ + ViewData["Title"] = "SubmittedForms"; +} + +<form method="post" > + <div class="container-lg"> + @{ + var id = Request.RouteValues["Id"]?.ToString(); + if (id is null) + { + } + } + <h1>@Model.Repository.GetProductForm(id).Title</h1> + <div> + @foreach (var submission in Model.Repository.GetSubmissionsForProductForm(Request.RouteValues["Id"].ToString())) + { + <div class="card mb-3 pt-0"> + <div class="card-body container row"> + @{ + foreach (var field in submission.FieldData) + { + <div class="col-4"> + <h5 class="card-title">@field.Key.Name</h5> + + <p>@field.Value</p> + </div> + + } + } + </div> + </div> + } + </div> + </div> +</form> + diff --git a/Rendelosch/Pages/SubmissionsPage.cshtml.cs b/Rendelosch/Pages/SubmissionsPage.cshtml.cs new file mode 100644 index 0000000..6d38262 --- /dev/null +++ b/Rendelosch/Pages/SubmissionsPage.cshtml.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; +using Rendelosch.Repository; + +namespace Rendelosch.Pages.Shared; + +public class SubmissionsPage : PageModel +{ + + public IProductFormRepository Repository { get; } + + public SubmissionsPage(IProductFormRepository repository) + { + Repository = repository; + } + + public void OnGet() + { + + } +} \ No newline at end of file diff --git a/Rendelosch/Pages/SubmitForm.cshtml b/Rendelosch/Pages/SubmitForm.cshtml index 597f221..fa12d01 100644 --- a/Rendelosch/Pages/SubmitForm.cshtml +++ b/Rendelosch/Pages/SubmitForm.cshtml @@ -9,15 +9,14 @@ <div class="container-lg"> <h1>@Model.Repository.GetProductForm(Request.RouteValues["Id"].ToString()).Title</h1> <div> - @foreach (var productForm in Model.Repository.GetProductForm(Request.RouteValues["Id"].ToString()).Fields) + @foreach (var field in Model.Repository.GetProductForm(Request.RouteValues["Id"].ToString()).Fields) { <div class="card-title col-6 m-0 me-3"> <Label > - @productForm.Name + @field.Name </Label> - <input class="form-control col-6"/> + <input class="form-control col-6" name="@field.Key"/> </div> - } <input class="btn btn-primary mt-4" type="submit"/> </div> diff --git a/Rendelosch/Pages/SubmitForm.cshtml.cs b/Rendelosch/Pages/SubmitForm.cshtml.cs index 3abfe63..eb38f65 100644 --- a/Rendelosch/Pages/SubmitForm.cshtml.cs +++ b/Rendelosch/Pages/SubmitForm.cshtml.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; using Rendelosch.Repository; namespace Rendelosch.Pages; @@ -12,8 +13,19 @@ public class SubmitForm : PageModel Repository = repository; } - public void OnPost() + public IActionResult OnPost() { - + var formId = Request.RouteValues["Id"]?.ToString(); + if (formId is null) return BadRequest(); + var dictionary = new Dictionary<string, string>(); + + foreach (var field in Repository.GetProductForm(formId)?.Fields) + { + if (Request.Form[field.Key] == "") return BadRequest(); + dictionary.Add(field.Key, Request.Form[field.Key]); + } + + Repository.AddSubmissionToProductForm(formId, dictionary); + return Redirect("/"); } } \ No newline at end of file -- GitLab