From 5af40e2ced0b43aace374480598079d6d3a04c7f Mon Sep 17 00:00:00 2001 From: Elijah Aremu <45821029+elielijah321@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:16:04 +0000 Subject: [PATCH 1/5] link an existing form a mat project --- .../DictionaryQuerystringExtensions.cs | 42 ++++++++++ .../Features/ApiClient.cs | 18 ++++- .../Features/IApiClient.cs | 2 + .../Features/PathFor.cs | 3 + .../Models/SetFormAMatProjectReference.cs | 19 +++++ .../AcademyConversionProjectRepository.cs | 19 +++++ .../IAcademyConversionProjectRepository.cs | 2 + .../Dfe.PrepareConversions/Models/Links.cs | 2 + .../IsProjectAlreadyInPreprare.cshtml | 58 ++++++++++++++ .../IsProjectAlreadyInPreprare.cshtml.cs | 69 ++++++++++++++++ .../Pages/NewProject/IsThisFormAMat.cshtml.cs | 2 +- .../NewProject/LinkFormAMatProject.cshtml | 53 +++++++++++++ .../NewProject/LinkFormAMatProject.cshtml.cs | 79 +++++++++++++++++++ .../Pages/NewProject/Summary.cshtml | 44 ++++++++--- .../Pages/NewProject/Summary.cshtml.cs | 25 +++++- ...emyConversionProjectItemsCacheDecorator.cs | 11 +++ 16 files changed, 435 insertions(+), 13 deletions(-) create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Extensions/DictionaryQuerystringExtensions.cs create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/SetFormAMatProjectReference.cs create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml.cs create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml.cs diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Extensions/DictionaryQuerystringExtensions.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Extensions/DictionaryQuerystringExtensions.cs new file mode 100644 index 000000000..ba8312f7b --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Extensions/DictionaryQuerystringExtensions.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.Encodings.Web; + +namespace Dfe.PrepareConversions.Data.Extensions +{ + public static class DictionaryQuerystringExtensions + { + /// + /// Converts a to an encoded querystring. + /// + /// + /// An containing parameter names (of + /// ) and values (of ) + /// + /// A defining whether the querystring should have a '?' prefix (default: true) + /// + /// A defining whether keys with null/empty values should be kept (default: + /// true) + /// + /// A string representing the parameters combined, UrlEncoded and (optionally) prefixed ready to be used in a URI + public static string ToQueryString(this IDictionary parameters, bool prefix = true, + bool keepEmpty = true) + { + IList parameterPairs = parameters + .Where(x => keepEmpty || string.IsNullOrWhiteSpace(x.Value) is false) + .Select(x => $"{Encode(x.Key)}={Encode(x.Value)}") + .ToList(); + + var prefixContent = prefix ? "?" : string.Empty; + + return parameterPairs.Count > 0 + ? $"{prefixContent}{string.Join("&", parameterPairs)}" + : string.Empty; + + string Encode(string x) + { + return string.IsNullOrWhiteSpace(x) ? string.Empty : UrlEncoder.Default.Encode(x); + } + } + } +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs index 80c48e4b5..f010bf126 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs @@ -1,6 +1,8 @@ -using Dfe.PrepareConversions.Data.Models; +using Dfe.PrepareConversions.Data.Extensions; +using Dfe.PrepareConversions.Data.Models; using Dfe.PrepareConversions.Data.Services; using Microsoft.FeatureManagement; +using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; @@ -143,4 +145,18 @@ public async Task GetFormAMatProjectsAsync(AcademyConversio return await AcademisationClient.PostAsync(PathFor.GetFormAMatProjects, JsonContent.Create(searchModel)); } + public async Task SearchFormAMatProjects(string searchTerm) + { + var queryParameters = new Dictionary + { + { "searchTerm", searchTerm }, + }; + + return await ActiveApplicationClient.GetAsync($"{PathFor.SearchFormAMatProjects}{queryParameters.ToQueryString()}"); + } + + public async Task SetFormAMatProjectReference(int id, SetFormAMatProjectReference setFormAMatProjectReference) + { + return await AcademisationClient.PutAsync(string.Format(PathFor.SetFormAMatProjectReference, id), JsonContent.Create(setFormAMatProjectReference)); + } } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs index 30bc974b9..09095ba11 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs @@ -23,4 +23,6 @@ public interface IApiClient Task SetPerformanceData(int id, SetPerformanceDataModel setPerformanceDataModel); Task SetIncomingTrust(int id, SetIncomingTrustDataModel setIncomingTrustDataModel); Task GetFormAMatProjectsAsync(AcademyConversionSearchModelV2 searchModel); + Task SearchFormAMatProjects(string searchTerm); + Task SetFormAMatProjectReference(int id, SetFormAMatProjectReference setFormAMatProjectReference); } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs index 17db66bb0..28dc5b1a9 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs @@ -27,4 +27,7 @@ public PathFor(IFeatureManager features) public static string GetAllProjectsV2 => "/conversion-project/projects"; public static string GetFormAMatProjects => "/conversion-project/FormAMatProjects"; + public static string SearchFormAMatProjects => "/conversion-project/search-formamatprojects"; + public static string SetFormAMatProjectReference => "/conversion-project/{0}/SetFormAMatProjectReference"; + } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/SetFormAMatProjectReference.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/SetFormAMatProjectReference.cs new file mode 100644 index 000000000..cc0499bca --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Models/SetFormAMatProjectReference.cs @@ -0,0 +1,19 @@ +namespace Dfe.PrepareConversions.Data.Models +{ + public class SetFormAMatProjectReference + { + public int ProjectId { get; set; } + public int FormAMatProjectId { get; set; } + + + public SetFormAMatProjectReference() { } + + public SetFormAMatProjectReference( + int projectId, + int formAMatProjectId) + { + ProjectId = projectId; + FormAMatProjectId = formAMatProjectId; + } + } +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs index 0d3e98142..7e3d086c0 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs @@ -323,4 +323,23 @@ public async Task SetIncomingTrust(int id, SetIncomingTrustDataModel setIncoming HttpResponseMessage result = await _apiClient.SetIncomingTrust(id, setIncomingTrustDataModel); if (result.IsSuccessStatusCode is false) throw new ApiResponseException($"Request to Api failed | StatusCode - {result.StatusCode}"); } + + public async Task>> SearchFormAMatProjects(string searchTerm) + { + HttpResponseMessage response = await _apiClient.SearchFormAMatProjects(searchTerm); + if (!response.IsSuccessStatusCode) + { + return new ApiResponse>(response.StatusCode, Enumerable.Empty()); + } + + IEnumerable outerResponse = await response.Content.ReadFromJsonAsync>(); + + return new ApiResponse>(response.StatusCode, outerResponse); + } + + public async Task SetFormAMatProjectReference(int id, SetFormAMatProjectReference setFormAMatProjectReference) + { + HttpResponseMessage result = await _apiClient.SetFormAMatProjectReference(id, setFormAMatProjectReference); + if (result.IsSuccessStatusCode is false) throw new ApiResponseException($"Request to Api failed | StatusCode - {result.StatusCode}"); + } } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs index 78faee7df..374752f0f 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs @@ -63,4 +63,6 @@ Task>>> GetFormAMatProject Task SetIncomingTrust(int id, SetIncomingTrustDataModel setIncomingTrustDataModel); Task> GetFilterParameters(); Task> AddProjectNote(int id, AddProjectNote addProjectNote); + Task>> SearchFormAMatProjects(string searchTerm); + Task SetFormAMatProjectReference(int id, SetFormAMatProjectReference setFormAMatProjectReference); } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Models/Links.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Models/Links.cs index d837d11b4..a9a021ff2 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Models/Links.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Models/Links.cs @@ -234,6 +234,8 @@ public static class NewProject public static readonly LinkItem SearchTrusts = AddLinkItem(page: "/NewProject/SearchTrust"); public static readonly LinkItem PreferredTrust = AddLinkItem(page: "/NewProject/PreferredTrust"); public static readonly LinkItem IsThisFormAMat = AddLinkItem(page: "/NewProject/IsThisFormAMat"); + public static readonly LinkItem IsProjectAlreadyInPrepare = AddLinkItem(page: "/NewProject/IsProjectAlreadyInPreprare"); + public static readonly LinkItem LinkFormAMatProject = AddLinkItem(page: "/NewProject/LinkFormAMatProject"); public static readonly LinkItem CreateNewFormAMat = AddLinkItem(page: "/NewProject/CreateNewFormAMat"); public static readonly LinkItem Summary = AddLinkItem(page: "/NewProject/Summary"); } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml new file mode 100644 index 000000000..260f99ac9 --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml @@ -0,0 +1,58 @@ +@page "/start-new-project/is-project-already-in-prepare" +@using Dfe.PrepareConversions.Pages.Shared +@model Dfe.PrepareConversions.Pages.SponsoredProject.IsProjectAlreadyInPreprareModel + +@{ + Layout = "_Layout"; + ViewBag.Title = (!ViewData.ModelState.IsValid ? "Error: " : "") + "Is the form a MAT/SAT project already in Prepare?"; + var routeParams = new Dictionary + { + { "urn", Request.Query["urn"] }, + { "ukprn", Request.Query["ukprn"] }, + { "hasSchoolApplied", Request.Query["hasSchoolApplied"] }, + { "isFormAMat" , Request.Query["isFormAMat"]}, + { "isProjectInPrepare" , Request.Query["isProjectInPrepare"]}, + }; +} + +@section BeforeMain + { + + +} + + + +
+
+
+ + + + +

Is the form a MAT/SAT project already in Prepare?

+ +
+
+
+ + +
+ +
+ + +
+
+
+ + +
+ +
diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml.cs new file mode 100644 index 000000000..fe8bed8fb --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsProjectAlreadyInPreprare.cshtml.cs @@ -0,0 +1,69 @@ +using Dfe.PrepareConversions.Data.Services; +using Dfe.PrepareConversions.Models; +using Dfe.PrepareConversions.Models.ProjectList; +using Dfe.PrepareConversions.Services; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.IdentityModel.Tokens; +using System.Threading.Tasks; +using EstablishmentDto = Dfe.Academies.Contracts.V4.Establishments.EstablishmentDto; + +namespace Dfe.PrepareConversions.Pages.SponsoredProject; + +public class IsProjectAlreadyInPreprareModel : PageModel +{ + private readonly ErrorService _errorService; + private readonly IGetEstablishment _getEstablishment; + + public IsProjectAlreadyInPreprareModel(IGetEstablishment getEstablishment, ErrorService errorService) + { + _getEstablishment = getEstablishment; + _errorService = errorService; + } + [BindProperty] + public string IsFormAMat { get; set; } + [BindProperty] + public string HasSchoolApplied { get; set; } + + [BindProperty] + public string IsProjectInPrepare { get; set; } + + public string Urn { get; set; } + + public async Task OnGet(string urn, string isFormAMat, string hasSchoolApplied, string isProjectInPrepare) + { + ProjectListFilters.ClearFiltersFrom(TempData); + HasSchoolApplied = hasSchoolApplied; + IsFormAMat = isFormAMat; + IsProjectInPrepare = isProjectInPrepare ?? "yes"; // Default to Yes if not used backlink to access + + EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn); + Urn = establishment.Urn; + + return Page(); + } + + public async Task OnPost(string ukprn, string urn, string redirect) + { + + if (IsProjectInPrepare.IsNullOrEmpty()) + { + _errorService.AddError("Does project exists", "Select yes if the project already exists in Prepare"); + return Page(); + } + string nextPage = null; + if (IsProjectInPrepare.ToLower() == "yes") + { + nextPage = Links.NewProject.LinkFormAMatProject.Page; + } + else + { + nextPage = Links.NewProject.CreateNewFormAMat.Page; + } + + + redirect = string.IsNullOrEmpty(redirect) ? nextPage : redirect; + + return RedirectToPage(redirect, new { ukprn, urn, HasSchoolApplied, IsFormAMat, IsProjectInPrepare }); + } +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsThisFormAMat.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsThisFormAMat.cshtml.cs index 1f131d4f4..e0c8ffd9a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsThisFormAMat.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/IsThisFormAMat.cshtml.cs @@ -50,7 +50,7 @@ public async Task OnPost(string ukprn, string urn, string redirec string nextPage = null; if (IsFormAMat.ToLower() == "yes") { - nextPage = Links.NewProject.CreateNewFormAMat.Page; + nextPage = Links.NewProject.IsProjectAlreadyInPrepare.Page; } else { diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml new file mode 100644 index 000000000..2c6b830ea --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml @@ -0,0 +1,53 @@ +@page "/start-new-project/link-project" +@using Dfe.PrepareConversions.Pages.Shared +@model Dfe.PrepareConversions.Pages.SponsoredProject.LinkFormAMatProject + +@{ + Layout = "_Layout"; + ViewBag.Title = (!ViewData.ModelState.IsValid ? "Error: " : "") + "Is this conversion part of the formation of a new trust?"; + var routeParams = new Dictionary + { + { "urn", Request.Query["urn"] }, + { "ukprn", Request.Query["ukprn"] }, + { "hasSchoolApplied", Request.Query["hasSchoolApplied"] }, + { "isFormAMat" , Request.Query["isFormAMat"]}, + { "isProjectInPrepare" , Request.Query["isProjectInPrepare"]}, + { "proposedTrustName" , Request.Query["ProposedTrustName"]}, + }; +} + +@section BeforeMain +{ + + +} + + + +
+
+
+ + + + + + + + +
+

+ +

+

Enter the trust name, application reference or FAM reference of the existing form a MAT/SAT project

+ +
+ + +
+ +
diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml.cs new file mode 100644 index 000000000..976d4db42 --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/LinkFormAMatProject.cshtml.cs @@ -0,0 +1,79 @@ +using Dfe.PrepareConversions.Data; +using Dfe.PrepareConversions.Data.Models; +using Dfe.PrepareConversions.Data.Services; +using Dfe.PrepareConversions.Models; +using Dfe.PrepareConversions.Models.ProjectList; +using Dfe.PrepareConversions.Services; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.IdentityModel.Tokens; +using System.Linq; +using System.Threading.Tasks; +using EstablishmentDto = Dfe.Academies.Contracts.V4.Establishments.EstablishmentDto; + +namespace Dfe.PrepareConversions.Pages.SponsoredProject; + +public class LinkFormAMatProject : PageModel +{ + private readonly ErrorService _errorService; + private readonly IGetEstablishment _getEstablishment; + private readonly IAcademyConversionProjectRepository _repository; + + public LinkFormAMatProject(IAcademyConversionProjectRepository repository, IGetEstablishment getEstablishment, ErrorService errorService) + { + _repository = repository; + _getEstablishment = getEstablishment; + _errorService = errorService; + } + [BindProperty] + public string IsFormAMat { get; set; } + [BindProperty] + public string IsProjectInPrepare { get; set; } + [BindProperty] + public string HasSchoolApplied { get; set; } + [BindProperty(Name = "application-reference")] + public string ApplicationReference { get; set; } + + + public string Urn { get; set; } + + public async Task OnGet(string urn, string isFormAMat, string hasSchoolApplied, string applicationReference, string isProjectInPrepare) + { + ProjectListFilters.ClearFiltersFrom(TempData); + HasSchoolApplied = hasSchoolApplied; + IsFormAMat = isFormAMat; + IsProjectInPrepare = isProjectInPrepare; + ApplicationReference = applicationReference ?? null; + + EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn); + Urn = establishment.Urn; + + return Page(); + } + + public async Task OnPost(string ukprn, string urn, string redirect) + { + if (ApplicationReference.IsNullOrEmpty() || ApplicationReference.Length <= 2) + { + _errorService.AddError("Application Reference", "Please enter a application reference with more than three characters"); + return Page(); + } + + var results = await _repository.SearchFormAMatProjects(ApplicationReference); + + if (!results.Success || results.Body.Count() == 0) + { + _errorService.AddError("Application Reference", "Could not find a project with those details"); + return Page(); + } + + var applicationReference = results.Body.First().ApplicationReference; + + var nextPage = Links.NewProject.Summary.Page; + + redirect = string.IsNullOrEmpty(redirect) ? nextPage : redirect; + + return RedirectToPage(redirect, new { ukprn, urn, HasSchoolApplied, IsFormAMat, IsProjectInPrepare, applicationReference }); + } +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml index d66cef5a1..b2348814d 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml @@ -166,16 +166,29 @@
@* Is this conversion part of a FAM? *@
-
- Is this conversion part of the formation of a new trust? -
-
- @Model.IsFormAMat.ToSentenceCase() -
-
+
+ Is this conversion part of the formation of a new trust? +
+
+ @Model.IsFormAMat.ToSentenceCase() +
+
-
-
+ +
+ + @* Is the project already in prepare? *@ +
+
+ Is the form a MAT/SAT project already in Prepare? +
+
+ @Model.IsProjectInPrepare.ToSentenceCase() +
+
+ +
+
@if (Model.ProposedTrustName != null) { @@ -200,6 +213,19 @@
+ @if (Model.ApplicationReference != null) + { +
+
+ Application Reference +
+
+ @Model.ApplicationReference +
+
+
+
+ } } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs index 0398e10c0..b0dde9b9b 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs @@ -1,8 +1,10 @@ using Dfe.Academies.Contracts.V4.Trusts; +using Dfe.PrepareConversions.Data.Models; using Dfe.PrepareConversions.Data.Services; using Dfe.PrepareConversions.Data.Services.Interfaces; using Dfe.PrepareConversions.Mappings; using Dfe.PrepareConversions.Models; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using System.Linq; @@ -31,9 +33,12 @@ public SummaryModel(IGetEstablishment getEstablishment, public string HasPreferredTrust { get; set; } public string ProposedTrustName { get; set; } public string IsFormAMat { get; set; } + public string IsProjectInPrepare { get; set; } + public string IsProjectAlreadyInPrepare { get; set; } + public string ApplicationReference { get; set; } - public async Task OnGetAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat) + public async Task OnGetAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat, string isProjectInPrepare, string applicationReference) { Establishment = await _getEstablishment.GetEstablishmentByUrn(urn); if (!string.IsNullOrEmpty(ukprn)) @@ -45,12 +50,20 @@ public async Task OnGetAsync(string urn, string ukprn, string has HasPreferredTrust = hasPreferredTrust; // Default to no as it's most common IsFormAMat = isFormAMat ?? "no"; + IsProjectInPrepare = isProjectInPrepare ?? "no"; ProposedTrustName = proposedTrustName ?? null; + ApplicationReference = applicationReference ?? null; + + if (ApplicationReference != null) + { + var results = await _academyConversionProjectRepository.SearchFormAMatProjects(ApplicationReference); + ProposedTrustName = results.Body.First().ProposedTrustName; + } return Page(); } - public async Task OnPostAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName) + public async Task OnPostAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string applicationReference) { Academies.Contracts.V4.Establishments.EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn); @@ -70,6 +83,14 @@ public async Task OnPostAsync(string urn, string ukprn, string ha else { await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust)); + + var results = await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference); + var formAMatProjectID = results.Body.First().Id; + + //TODO:EA : get the actual project ID that was just created + int projectId = 1; + + await _academyConversionProjectRepository.SetFormAMatProjectReference(projectId, new SetFormAMatProjectReference(projectId, formAMatProjectID)); } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs index 30f4641d7..85944b149 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs @@ -2,6 +2,7 @@ using Dfe.PrepareConversions.Data.Models; using Dfe.PrepareConversions.Data.Models.NewProject; using Dfe.PrepareConversions.Data.Services; +using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; @@ -126,4 +127,14 @@ public async Task SetIncomingTrust(int id, SetIncomingTrustDataModel setIncoming { await _innerRepository.SetIncomingTrust(id, setIncomingTrustDataModel); } + + public async Task>> SearchFormAMatProjects(string searchTerm) + { + return await _innerRepository.SearchFormAMatProjects(searchTerm); + } + + public async Task SetFormAMatProjectReference(int id, SetFormAMatProjectReference setFormAMatProjectReference) + { + await _innerRepository.SetFormAMatProjectReference(id, setFormAMatProjectReference); + } } From 5f05df33f5969207248b06c0ffa07640fd774bcf Mon Sep 17 00:00:00 2001 From: Elijah Aremu <45821029+elielijah321@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:13:23 +0000 Subject: [PATCH 2/5] tweaking logic in summary --- .../AcademyConversionProjectRepository.cs | 12 +++++++--- .../IAcademyConversionProjectRepository.cs | 2 +- .../Pages/NewProject/Summary.cshtml.cs | 23 ++++++++++--------- ...emyConversionProjectItemsCacheDecorator.cs | 5 ++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs index 7e3d086c0..f1232c2cb 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs @@ -93,16 +93,22 @@ public async Task> UpdateProject(int id, U return new ApiResponse(updateResponse.StatusCode, project); } - public async Task CreateProject(CreateNewProject newProject) + public async Task> CreateProject(CreateNewProject newProject) { HttpClient httpClient = _httpClientFactory.CreateAcademisationClient(); - ApiResponse result = await _httpClientService.Post( + ApiResponse result = await _httpClientService.Post( httpClient, @"legacy/project/new-conversion-project", newProject); - if (result.Success is false) throw new ApiResponseException($"Request to Api failed | StatusCode - {result.StatusCode}"); + if (!result.Success) + { + throw new ApiResponseException($"Request to Api failed | StatusCode - {result.StatusCode}"); + } + + return new ApiResponse(result.StatusCode, result.Body); + } public async Task CreateFormAMatProject(CreateNewFormAMatProject newProject) { diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs index 374752f0f..dc51f1b9a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs @@ -53,7 +53,7 @@ Task>>> GetFormAMatProject Task> GetProjectById(int id); Task> GetFormAMatProjectById(int id); Task> UpdateProject(int id, UpdateAcademyConversionProject updateProject); - Task CreateProject(CreateNewProject newProject); + Task> CreateProject(CreateNewProject newProject); Task CreateFormAMatProject(CreateNewFormAMatProject newProject); Task SetProjectExternalApplicationForm(int id, bool externalApplicationFormSaved, string externalApplicationFormUrl); Task SetAssignedUser(int id, SetAssignedUserModel updatedAssignedUser); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs index b0dde9b9b..85ca0247a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs @@ -63,7 +63,7 @@ public async Task OnGetAsync(string urn, string ukprn, string has return Page(); } - public async Task OnPostAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string applicationReference) + public async Task OnPostAsync(string urn, string ukprn, string hasSchoolApplied, string hasPreferredTrust, string proposedTrustName, string isFormAMat, string applicationReference) { Academies.Contracts.V4.Establishments.EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn); @@ -72,26 +72,27 @@ public async Task OnPostAsync(string urn, string ukprn, string ha { trust = await _trustRepository.GetTrustByUkprn(ukprn); } + if (proposedTrustName != null) { trust.Name = proposedTrustName; - } - if (proposedTrustName != null) - { await _academyConversionProjectRepository.CreateFormAMatProject(CreateProjectMapper.MapFormAMatToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust)); } - else + + if(isFormAMat.ToLower() == "yes" && proposedTrustName == null) { - await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust)); - - var results = await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference); - var formAMatProjectID = results.Body.First().Id; + var createdProject = (await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust))); + var formAMatProject = (await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference)); - //TODO:EA : get the actual project ID that was just created - int projectId = 1; + int projectId = createdProject.Body.Id; + var formAMatProjectID = formAMatProject.Body.First().Id; await _academyConversionProjectRepository.SetFormAMatProjectReference(projectId, new SetFormAMatProjectReference(projectId, formAMatProjectID)); } + else + { + await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust)); + } return RedirectToPage(Links.ProjectList.Index.Page); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs index 85944b149..b1630f60c 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs @@ -63,9 +63,10 @@ public async Task> GetFormAMatProjectById(int id) ApiResponse project = await _innerRepository.GetFormAMatProjectById(id); return project; } - public async Task CreateProject(CreateNewProject sponsoredProject) + public async Task> CreateProject(CreateNewProject sponsoredProject) { - await _innerRepository.CreateProject(sponsoredProject); + ApiResponse project = await _innerRepository.CreateProject(sponsoredProject); + return project; } public async Task CreateFormAMatProject(CreateNewFormAMatProject sponsoredProject) { From 1d2fa1fecddb4165fccfe41b87eb10e6a7b85994 Mon Sep 17 00:00:00 2001 From: Elijah Aremu <45821029+elielijah321@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:15:39 +0000 Subject: [PATCH 3/5] fix summary page --- .../Pages/NewProject/Summary.cshtml | 136 +++++++++--------- .../Pages/NewProject/Summary.cshtml.cs | 10 +- 2 files changed, 78 insertions(+), 68 deletions(-) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml index 45c0e2c44..33f055d1a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml @@ -163,34 +163,33 @@ ChangeTrust name - - @* Is this conversion part of a FAM? *@ -
-
- Is this conversion part of the formation of a new trust? -
-
- @Model.IsFormAMat.ToSentenceCase() -
-
- -
-
- - @* Is the project already in prepare? *@ -
-
- Is the form a MAT/SAT project already in Prepare? -
-
- @Model.IsProjectInPrepare.ToSentenceCase() -
-
- -
-
- + @* Is this conversion part of a FAM? *@ +
+
+ Is this conversion part of the formation of a new trust? +
+
+ @Model.IsFormAMat.ToSentenceCase() +
+
+ +
+
+ + @* Is the project already in prepare? *@ +
+
+ Is the form a MAT/SAT project already in Prepare? +
+
+ @Model.IsProjectInPrepare.ToSentenceCase() +
+
+ +
+
+ @if (Model.HasSchoolApplied.ToLower().Equals("no") && Model.IsFormAMat.ToLower().Equals("no")) {
@@ -204,9 +203,10 @@
} + + - - @if (Model.ProposedTrustName != null) + @if (Model.Trust != null) {
@@ -224,28 +224,42 @@ Name
- @Model.ProposedTrustName + @Model.Trust.Name
+ + ChangeTrust name + +
+
+ +
+
+ UKPRN +
+
+ @Model.Trust.Ukprn +
+
+
+ +
+
+ Companies House Number +
+
+ @Model.Trust.CompaniesHouseNumber
+
- @if (Model.ApplicationReference != null) - { -
-
- Application Reference -
-
- @Model.ApplicationReference -
-
-
-
- } + + } - @if (Model.Trust != null) + + @if (Model.ApplicationReference != null) {
@@ -262,35 +276,25 @@
Name
-
- @Model.Trust.Name -
-
- - ChangeTrust name - -
-
- -
-
- UKPRN -
- @Model.Trust.Ukprn + @Model.ProposedTrustName
- Companies House Number + A2B Reference
-
- @Model.Trust.CompaniesHouseNumber +
+ @Model.ApplicationReference +
+
+ + ChangeA2B reference +
-
@@ -298,6 +302,10 @@ } + + + +
diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs index 85ca0247a..965506260 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs @@ -78,11 +78,13 @@ public async Task OnPostAsync(string urn, string ukprn, string ha trust.Name = proposedTrustName; await _academyConversionProjectRepository.CreateFormAMatProject(CreateProjectMapper.MapFormAMatToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust)); } - - if(isFormAMat.ToLower() == "yes" && proposedTrustName == null) + + bool _isFormAMAT = isFormAMat.ToLower().Equals("yes"); + + if (_isFormAMAT && proposedTrustName == null) { - var createdProject = (await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust))); - var formAMatProject = (await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference)); + var createdProject = await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust, _isFormAMAT)); + var formAMatProject = await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference); int projectId = createdProject.Body.Id; var formAMatProjectID = formAMatProject.Body.First().Id; From da3393cf98cdaae03282b2729f7c20f50d57ce23 Mon Sep 17 00:00:00 2001 From: Dominic NEED Date: Thu, 28 Mar 2024 12:49:10 +0000 Subject: [PATCH 4/5] Adding margin to the continue button --- .../Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml | 2 +- .../Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml index 33f055d1a..0add91dd5 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml @@ -306,7 +306,7 @@
-
+
diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs index 965506260..a569d5d7a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/NewProject/Summary.cshtml.cs @@ -4,7 +4,6 @@ using Dfe.PrepareConversions.Data.Services.Interfaces; using Dfe.PrepareConversions.Mappings; using Dfe.PrepareConversions.Models; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using System.Linq; @@ -83,7 +82,7 @@ public async Task OnPostAsync(string urn, string ukprn, string ha if (_isFormAMAT && proposedTrustName == null) { - var createdProject = await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust, _isFormAMAT)); + var createdProject = await _academyConversionProjectRepository.CreateProject(CreateProjectMapper.MapToDto(establishment, trust, hasSchoolApplied, hasPreferredTrust, true)); var formAMatProject = await _academyConversionProjectRepository.SearchFormAMatProjects(applicationReference); int projectId = createdProject.Body.Id; From 1f0c4f881902493c066b326c38c6393dd2dfb2b7 Mon Sep 17 00:00:00 2001 From: Elijah Aremu <45821029+elielijah321@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:32:11 +0100 Subject: [PATCH 5/5] fix broken unit tests --- .../AcademyConversionProjectRepositoryTests.cs | 10 +++++----- .../Services/AcademyConversionProjectRepository.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data.Tests/Services/AcademyConversionProjectRepositoryTests.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data.Tests/Services/AcademyConversionProjectRepositoryTests.cs index 2e9bf0a60..01114b21a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data.Tests/Services/AcademyConversionProjectRepositoryTests.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data.Tests/Services/AcademyConversionProjectRepositoryTests.cs @@ -95,14 +95,14 @@ public void GivenDeliveryOfficers_GetsNoProjects_WhenDeliveryOfficerHasNoneAssig [AutoMoqData] public async Task GivenAValidProject_PostToApi([Frozen] Mock httpService, AcademyConversionProjectRepository subject) { - httpService.Setup(m => m.Post( + httpService.Setup(m => m.Post( It.IsAny(), @"legacy/project/new-conversion-project", It.IsAny())) - .ReturnsAsync(new ApiResponse(HttpStatusCode.OK, string.Empty)); + .ReturnsAsync(new ApiResponse(HttpStatusCode.OK, It.IsAny())); CreateNewProject project = new(null, null, null, null, false); await subject.CreateProject(project); - httpService.Verify(m => m.Post( + httpService.Verify(m => m.Post( It.IsAny(), @"legacy/project/new-conversion-project", project), Times.Once); } @@ -110,9 +110,9 @@ public async Task GivenAValidProject_PostToApi([Frozen] Mock [AutoMoqData] public async Task GivenAFailedResponse_ThrowAnException([Frozen] Mock httpService, AcademyConversionProjectRepository subject) { - httpService.Setup(m => m.Post( + httpService.Setup(m => m.Post( It.IsAny(), @"legacy/project/new-conversion-project", It.IsAny())) - .ReturnsAsync(new ApiResponse(HttpStatusCode.InternalServerError, string.Empty)); + .ReturnsAsync(new ApiResponse(HttpStatusCode.InternalServerError, null)); CreateNewProject project = new(null, null, null, null, false); ApiResponseException exception = await Assert.ThrowsAsync(() => subject.CreateProject(project)); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs index f1232c2cb..6e8eec830 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs @@ -102,7 +102,7 @@ public async Task> CreateProject(CreateNew @"legacy/project/new-conversion-project", newProject); - if (!result.Success) + if (result.Success is false) { throw new ApiResponseException($"Request to Api failed | StatusCode - {result.StatusCode}"); }