Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Adding caveat solicitor question.
Browse files Browse the repository at this point in the history
  • Loading branch information
william-finance-ni committed Nov 2, 2021
1 parent 2860e67 commit 689c1e5
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 0 deletions.
102 changes: 102 additions & 0 deletions Controllers/CaveatController.cs
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 });
}
}
}
68 changes: 68 additions & 0 deletions Helpers/HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,40 @@ public static string GetCitizenLink(string environment)
return urlToReturn;
}

/// <summary>
/// This determines what env the app is in and provides the citizen link to the app for caveat.
/// </summary>
/// <param name="environment"></param>
/// <returns></returns>
public static string GetCitizenLinkCaveat(string environment)
{
string urlToReturn = string.Empty;

switch (environment)
{
case "Development":
urlToReturn = "https://nicts-probate-sandbox.london.cloudapps.digital/Caveat";
break;

case "Sandbox":
urlToReturn = "https://nicts-probate-sandbox.london.cloudapps.digital/Caveat";
break;

case "Staging":
urlToReturn = "https://nicts-probate-staging.london.cloudapps.digital/Caveat";
break;

case "Production":
urlToReturn = "https://apply-for-probate.nidirect.gov.uk/Caveat";
break;

default:
break;
}

return urlToReturn;
}

/// <summary>
/// This determines what env the app is in and provides the solicitor link to the app.
/// </summary>
Expand Down Expand Up @@ -72,5 +106,39 @@ public static string GetSolicitorLink(string environment)

return urlToReturn;
}

/// <summary>
/// This determines what env the app is in and provides the solicitor link to the app for caveat.
/// </summary>
/// <param name="environment"></param>
/// <returns></returns>
public static string GetSolicitorLinkCaveat(string environment)
{
string urlToReturn = string.Empty;

switch (environment)
{
case "Development":
urlToReturn = "https://nicts-probate-solicitor-sandbox.london.cloudapps.digital/Caveat";
break;

case "Sandbox":
urlToReturn = "https://nicts-probate-solicitor-sandbox.london.cloudapps.digital/Caveat";
break;

case "Staging":
urlToReturn = "https://nicts-probate-solicitor-staging.london.cloudapps.digital/Caveat";
break;

case "Production":
urlToReturn = "https://apply-for-probate-professional.nidirect.gov.uk/Caveat";
break;

default:
break;
}

return urlToReturn;
}
}
}
38 changes: 38 additions & 0 deletions Views/Caveat/Question.cshtml
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>
3 changes: 3 additions & 0 deletions Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</h1>
<p class="govuk-body">
<a href="@Url.Action("Index", "Probate")" class="govuk-link">Check eligibility for probate</a>
<br />
<br />
<a href="@Url.Action("Index", "Caveat")" class="govuk-link">Check eligibility for caveat</a>
</p>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions wwwroot/config/CaveatQuestions.json
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"
}


]

0 comments on commit 689c1e5

Please sign in to comment.