diff --git a/Rendelosch/Pages/Index.cshtml b/Rendelosch/Pages/Index.cshtml index 01e97a7975b8df7c3d5d168340bcd5b23d080528..5f953a669ee64673e5aa624fb16629336e66d1cf 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 0000000000000000000000000000000000000000..b3864a4d2bae06b2911908c9526cfea392c71195 --- /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 0000000000000000000000000000000000000000..6d3826214da627378b8011ca6a3e6f9b16cd5b47 --- /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 597f2219a6beb1fd125805e26a825e8387d7ad4b..fa12d01b649e7d6774f451d722dbd71434221efe 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 3abfe6356b3a809e436ef4c7b4407820369b034a..eb38f65043ba67086f38d0c9a6b4c99f7b576d37 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