This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from dof-dss/William-Sprint
Adding caveat solicitor question.
- Loading branch information
Showing
5 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using eligibility_checker.Models; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace eligibility_checker.Controllers | ||
{ | ||
public class CaveatController : Controller | ||
{ | ||
private readonly IWebHostEnvironment _env; | ||
|
||
public CaveatController(IWebHostEnvironment env) | ||
{ | ||
_env = env; | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Index(string page) | ||
{ | ||
ViewBag.ServiceName = "Apply for Caveat"; | ||
|
||
if (string.IsNullOrWhiteSpace(page)) | ||
{ | ||
// Start | ||
var model = GetPage("start"); | ||
var viewModel = new PageViewModel(model); | ||
return View(model.Template, viewModel); | ||
|
||
} | ||
else | ||
{ | ||
if (page == "solicitor-redirect") | ||
{ | ||
return Redirect(Helpers.HelperMethods.GetSolicitorLinkCaveat(_env.EnvironmentName)); | ||
} | ||
|
||
if (page == "citizen-redirect") | ||
{ | ||
return Redirect(Helpers.HelperMethods.GetCitizenLinkCaveat(_env.EnvironmentName)); | ||
} | ||
|
||
var model = GetPage(page); | ||
var viewModel = new PageViewModel(model); | ||
|
||
return View(model.Template, viewModel); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public IActionResult Index(bool answer, string page) | ||
{ | ||
ViewBag.ServiceName = "Apply for Caveat"; | ||
|
||
var source = GetPage(page); | ||
if (answer) | ||
{ | ||
return RedirectToAction("Index", new { page = source.OnYes }); | ||
} | ||
else | ||
{ | ||
return RedirectToAction("Index", new { page = source.OnNo }); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult Accessibility() | ||
{ | ||
ViewBag.ServiceName = "Check eligibility"; | ||
|
||
var model = GetPage("Accessibility"); | ||
model.Header = "Accessibility"; | ||
var viewModel = new PageViewModel(model); | ||
return View(viewModel); | ||
} | ||
|
||
private PageModel GetPage(string page) | ||
{ | ||
var list = GetPages(); | ||
return list.First(item => item.Page.ToLower() == page.ToLower()); | ||
} | ||
|
||
private List<PageModel> GetPages() | ||
{ | ||
var folderDetails = Path.Combine(Directory.GetCurrentDirectory(), $"wwwroot//{"config//CaveatQuestions.json"}"); | ||
var json = System.IO.File.ReadAllText(folderDetails); | ||
var list = JsonConvert.DeserializeObject<List<PageModel>>(json); | ||
return list; | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
ViewBag.ServiceName = "Apply for Caveat"; | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@model eligibility_checker.Models.PageViewModel | ||
|
||
<form method="post" asp-controller="Caveat" asp-action="Index" | ||
asp-route-page="@Model.Page"> | ||
@Html.AntiForgeryToken() | ||
|
||
@if (Model.Page != "start") | ||
{ | ||
<a href="javascript:history.go(-1)" class="govuk-back-link">Back</a> | ||
} | ||
|
||
<partial name="../Components/_errorSummary.cshtml" /> | ||
|
||
<div class="govuk-form-group"> | ||
<fieldset class="govuk-fieldset" aria-describedby="changed-name-hint"> | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l"> | ||
<h1 class="govuk-fieldset__heading">@Model.Header</h1> | ||
</legend> | ||
|
||
|
||
<span asp-validation-for="Answer" class="govuk-error-message"> | ||
</span> | ||
<div id="changed-name-hint" class="govuk-hint">@Html.Raw(Model.Hint)</div> | ||
<div class="govuk-radios govuk-radios--inline"> | ||
<div class="govuk-radios__item"> | ||
<input class="govuk-radios__input" id="answer" name="answer" type="radio" value="true" data-val="true" data-val-required="@Model.Validation"> | ||
<label class="govuk-label govuk-radios__label" for="answer">Yes</label> | ||
</div> | ||
<div class="govuk-radios__item"> | ||
<input class="govuk-radios__input" id="answer-2" name="answer" type="radio" value="false"> | ||
<label class="govuk-label govuk-radios__label" for="answer-2">No</label> | ||
</div> | ||
</div> | ||
|
||
</fieldset> | ||
</div> | ||
<input type="submit" value="Continue" name="save" class="govuk-button" data-module="govuk-button" /> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"Page": "start", | ||
"Template": "Question", | ||
"Header": "Are you a Solicitor acting on behalf of a client in this application?", | ||
"Validation": "Answer 'Yes' if you are a solicitor, 'No' if you are a citizen applying", | ||
"OnYes": "solicitor-redirect", | ||
"OnNo": "citizen-redirect" | ||
} | ||
|
||
|
||
] |