Skip to content

Commit 4989696

Browse files
TD-988: Edit centre issues resolved.
1. Null value is not inserting in date field 2. Dropdown values not retaining
1 parent 327d823 commit 4989696

File tree

6 files changed

+127
-50
lines changed

6 files changed

+127
-50
lines changed

DigitalLearningSolutions.Data/DataServices/CentresDataService.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ public void UpdateCentreRoleLimits(
763763
c.CentreName,
764764
ct.ContractTypeID,
765765
ct.ContractType,
766-
ct.ServerSpaceBytesInc,
767-
ct.DelegateUploadSpace,
766+
c.ServerSpaceBytes ServerSpaceBytesInc,
767+
c.CandidateByteLimit DelegateUploadSpace,
768768
c.ContractReviewDate
769769
FROM Centres AS c
770770
INNER JOIN ContractTypes AS ct ON ct.ContractTypeID = c.ContractTypeId
@@ -776,11 +776,6 @@ FROM Centres AS c
776776
logger.LogWarning($"No centre found for centre id {centreId}");
777777
return null;
778778
}
779-
if (centre.ContractReviewDate == null)
780-
{
781-
centre.ContractReviewDate = DateTime.Now;
782-
return centre;
783-
}
784779
return centre;
785780
}
786781
public bool UpdateContractTypeandCenter(

DigitalLearningSolutions.Web.Tests/Controllers/SuperAdmin/CentresControllerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void Get_with_centreId_shows_EditContractInfo_page()
221221
A.CallTo(() => centresDataService.GetContractInfo(CenterId)).Returns(CentreContractAdminUsageTestHelper.GetDefaultEditContractInfo(CenterId));
222222

223223
// When
224-
var result = controller.EditContractInfo(centreId);
224+
var result = controller.EditContractInfo(centreId,21,8,2023);
225225

226226
// Then
227227
using (new AssertionScope())
@@ -259,7 +259,7 @@ public void Edit_ContractInfo_redirects_with_successful_save()
259259
DateTime date = new DateTime(model.ContractReviewYear.Value, model.ContractReviewMonth.Value, model.ContractReviewDay.Value, 0, 0, 0);
260260

261261
// When
262-
var result = controller.EditContractInfo(model);
262+
var result = controller.EditContractInfo(model,21,8,2023);
263263

264264
// Then
265265

DigitalLearningSolutions.Web/Controllers/SuperAdmin/Centres/CentresController.cs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -450,59 +450,76 @@ public IActionResult AddCentre(AddCentreSuperAdminViewModel model)
450450
[HttpGet]
451451
[NoCaching]
452452
[Route("SuperAdmin/Centres/{centreId=0:int}/EditContractInfo")]
453-
public IActionResult EditContractInfo(int centreId = 0)
453+
public IActionResult EditContractInfo(int centreId , int? day, int? month, int? year)
454454
{
455455
ContractInfo centre = this.centresDataService.GetContractInfo(centreId);
456456
var contractTypes = this.contractTypesDataService.GetContractTypes().ToList();
457457
var serverspace = this.contractTypesDataService.GetServerspace();
458458
var delegatespace = this.contractTypesDataService.Getdelegatespace();
459459

460-
ViewBag.Serverspace = SelectListHelper.MapLongOptionsToSelectListItems(
460+
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
461+
centre.ContractTypeID, centre.ContractType,
462+
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
463+
centre.ContractReviewDate,day,month,year);
464+
model.ServerSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
461465
serverspace, centre.ServerSpaceBytesInc
462466
);
463-
ViewBag.Delegatespace = SelectListHelper.MapLongOptionsToSelectListItems(
467+
model.PerDelegateUploadSpaceOptions= SelectListHelper.MapLongOptionsToSelectListItems(
464468
delegatespace, centre.DelegateUploadSpace
465469
);
466-
ViewBag.ContractTypes = SelectListHelper.MapOptionsToSelectListItems(
470+
model.ContractTypeOptions= SelectListHelper.MapOptionsToSelectListItems(
467471
contractTypes, centre.ContractTypeID
468472
);
469-
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
470-
centre.ContractTypeID, centre.ContractType,
471-
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
472-
centre.ContractReviewDate, centre.ContractReviewDate.Value.Day,
473-
centre.ContractReviewDate.Value.Month, centre.ContractReviewDate.Value.Year);
473+
if (day != null && month != null && year != null)
474+
{
475+
model.CompleteByValidationResult = OldDateValidator.ValidateDate(day.Value, month.Value, year.Value);
476+
}
474477
return View(model);
475478
}
476479

477480

478481
[Route("SuperAdmin/Centres/{centreId=0:int}/EditContractInfo")]
479482
[HttpPost]
480-
public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewModel)
483+
public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewModel,int? day,int? month,int? year)
481484
{
482-
if (!ModelState.IsValid)
485+
if (day != 0 | month != 0 | year != 0)
486+
{
487+
var validationResult = OldDateValidator.ValidateDate(day??0, month??0, year??0);
488+
if (!validationResult.DateValid)
489+
{
490+
if (day == null) day = 0;
491+
if(month == null) month = 0;
492+
if (year == null) year= 0;
493+
return RedirectToAction("EditContractInfo", new { contractTypeViewModel.CentreId, day, month, year });
494+
}
495+
}
496+
if (!ModelState.IsValid)
483497
{
484498
ContractInfo centre = this.centresDataService.GetContractInfo(contractTypeViewModel.CentreId);
485499
var contractTypes = this.contractTypesDataService.GetContractTypes().ToList();
486500
var serverspace = this.contractTypesDataService.GetServerspace();
487501
var delegatespace = this.contractTypesDataService.Getdelegatespace();
488502

489-
ViewBag.Serverspace = SelectListHelper.MapLongOptionsToSelectListItems(
490-
serverspace, centre.ServerSpaceBytesInc
491-
);
492-
ViewBag.Delegatespace = SelectListHelper.MapLongOptionsToSelectListItems(
493-
delegatespace, centre.DelegateUploadSpace
494-
);
495-
ViewBag.ContractTypes = SelectListHelper.MapOptionsToSelectListItems(
496-
contractTypes, centre.ContractTypeID
497-
);
498503
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
499504
centre.ContractTypeID, centre.ContractType,
500505
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
501-
centre.ContractReviewDate, centre.ContractReviewDate.Value.Day,
502-
centre.ContractReviewDate.Value.Month, centre.ContractReviewDate.Value.Year);
506+
centre.ContractReviewDate, day,month,year);
507+
model.ServerSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
508+
serverspace, model.ServerSpaceBytesInc
509+
);
510+
model.PerDelegateUploadSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
511+
delegatespace, model.DelegateUploadSpace
512+
);
513+
model.ContractTypeOptions = SelectListHelper.MapOptionsToSelectListItems(
514+
contractTypes, model.ContractTypeID
515+
);
503516
return View(model);
504517
}
505-
DateTime date = new DateTime(contractTypeViewModel.ContractReviewYear.Value, contractTypeViewModel.ContractReviewMonth.Value, contractTypeViewModel.ContractReviewDay.Value, 0, 0, 0);
518+
DateTime? date = null;
519+
if(day!=null&&month!=null&year!=null)
520+
{
521+
date = new DateTime(year ?? 0, month ?? 0, day ?? 0);
522+
}
506523
this.centresDataService.UpdateContractTypeandCenter(contractTypeViewModel.CentreId,
507524
contractTypeViewModel.ContractTypeID,
508525
contractTypeViewModel.DelegateUploadSpace,

DigitalLearningSolutions.Web/ViewModels/SuperAdmin/Centres/ContractTypeViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

22
namespace DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres
33
{
4+
using DigitalLearningSolutions.Web.Helpers;
5+
using Microsoft.AspNetCore.Mvc.Rendering;
46
using System;
7+
using System.Collections.Generic;
8+
59
public class ContractTypeViewModel
610
{
711
public ContractTypeViewModel()
@@ -36,7 +40,10 @@ public ContractTypeViewModel(
3640
public int? ContractReviewDay { get; set; }
3741
public int? ContractReviewMonth { get; set; }
3842
public int? ContractReviewYear { get; set; }
39-
43+
public OldDateValidator.ValidationResult? CompleteByValidationResult { get; set; }
44+
public IEnumerable<SelectListItem> ContractTypeOptions { get; set; } = new List<SelectListItem>();
45+
public IEnumerable<SelectListItem> ServerSpaceOptions { get; set; } = new List<SelectListItem>();
46+
public IEnumerable<SelectListItem> PerDelegateUploadSpaceOptions { get; set; } = new List<SelectListItem>();
4047

4148
}
4249
}

DigitalLearningSolutions.Web/Views/SuperAdmin/Centres/EditContractInfo.cshtml

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
1-
@using DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres
1+
@using DigitalLearningSolutions.Data.Utilities;
2+
@using DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Centres
3+
@inject IClockUtility ClockUtility
24
@model ContractTypeViewModel
35
@{
46
var errorHasOccurred = !ViewData.ModelState.IsValid;
57
ViewData["Title"] = errorHasOccurred ? "Error: Edit Contract Info" : "Edit Contract Info";
6-
8+
var exampleDate = ClockUtility.UtcToday;
79
var hintTextLines = new List<string> {
8-
$"For example, {@Model.ContractReviewDay} {@Model.ContractReviewMonth} {@Model.ContractReviewYear}. Leave the boxes blank to clear the contract review date.",
10+
$"For example, {@exampleDate.Day} {@exampleDate.Month} { @exampleDate.Year}. Leave the boxes blank to clear the contract review date.",
911
" ", };
1012
}
11-
1213
@if (errorHasOccurred)
1314
{
1415
<vc:error-summary order-of-property-names="@(new string[] { nameof(Model.CentreName),nameof(Model.ContractType)})" />
1516
}
16-
17+
@{
18+
string contractReviewDay;
19+
string ContractReviewMonth;
20+
string ContractReviewYear;
21+
if (Model.CompleteByValidationResult?.DateValid == false)
22+
{
23+
contractReviewDay = Model.CompleteByValidationResult?.Day.ToString() ?? "";
24+
ContractReviewMonth = Model.CompleteByValidationResult?.Month.ToString() ?? "";
25+
ContractReviewYear = Model.CompleteByValidationResult?.Year.ToString() ?? "";
26+
contractReviewDay = contractReviewDay == "0" ? "" : contractReviewDay;
27+
ContractReviewMonth = ContractReviewMonth == "0" ? "" : ContractReviewMonth;
28+
ContractReviewYear = ContractReviewYear == "0" ? "" : ContractReviewYear;
29+
}
30+
else
31+
{
32+
contractReviewDay = Model.ContractReviewDate?.Day.ToString() ?? "";
33+
ContractReviewMonth = Model.ContractReviewDate?.Month.ToString() ?? "";
34+
ContractReviewYear = Model.ContractReviewDate?.Year.ToString() ?? "";
35+
}
36+
37+
38+
var dayErrorClass = Model.CompleteByValidationResult?.DayValid == false ? "nhsuk-input--error" : "";
39+
var monthErrorClass = Model.CompleteByValidationResult?.MonthValid == false ? "nhsuk-input--error" : "";
40+
var yearErrorClass = Model.CompleteByValidationResult?.YearValid == false ? "nhsuk-input--error" : "";
41+
var formErrorClass = Model.CompleteByValidationResult?.DateValid == false ? "nhsuk-form-group--error" : "";
42+
}
1743

1844
<div id="form-group">
1945
<h1 class="nhsuk-heading-xl">Edit contract info for @Model.CentreName </h1>
@@ -32,7 +58,7 @@
3258
required="true"
3359
css-class="nhsuk-u-width-one-half"
3460
default-option=""
35-
select-list-options="@ViewBag.ContractTypes" />
61+
select-list-options="@Model.ContractTypeOptions" />
3662

3763
<vc:select-list asp-for="@nameof(Model.ServerSpaceBytesInc)"
3864
label="Server space"
@@ -41,7 +67,7 @@
4167
required="true"
4268
css-class="nhsuk-u-width-one-half"
4369
default-option=""
44-
select-list-options="@ViewBag.Serverspace" />
70+
select-list-options="@Model.ServerSpaceOptions" />
4571

4672
<vc:select-list asp-for="@nameof(Model.DelegateUploadSpace)"
4773
label=" Per delegate upload space"
@@ -50,16 +76,48 @@
5076
required="true"
5177
css-class="nhsuk-u-width-one-half"
5278
default-option=""
53-
select-list-options="@ViewBag.Delegatespace" />
54-
<vc:date-input id="complete-by-date"
55-
label="Contract review date"
56-
day-id="ContractReviewDay"
57-
month-id="ContractReviewMonth"
58-
year-id="ContractReviewYear"
59-
css-class="nhsuk-u-margin-bottom-2"
60-
hint-text-lines="@hintTextLines" />
61-
79+
select-list-options="@Model.PerDelegateUploadSpaceOptions" />
80+
<fieldset class="nhsuk-fieldset" aria-labelledby="form-heading" aria-describedby="example-hint" role="group">
81+
<legend class="nhsuk-fieldset__legend nhsuk-label">
82+
Contract review date
83+
</legend>
84+
<span class="nhsuk-hint" id="example-hint">
85+
For example, @exampleDate.Day @exampleDate.Month @exampleDate.Year. Leave the boxes blank to clear the contract review date..
86+
</span>
87+
@if (Model.CompleteByValidationResult?.DateValid == false)
88+
{
89+
<span class="nhsuk-error-message" id="validation-message" role="alert">
90+
<span class="nhsuk-u-visually-hidden">Error:</span>@Model.CompleteByValidationResult?.ErrorMessage
91+
</span>
92+
}
93+
<div class="nhsuk-date-input" id="date">
94+
<div class="nhsuk-date-input__item">
95+
<div class="nhsuk-form-group">
96+
<label class="nhsuk-label nhsuk-date-input__label" for="day">
97+
Day
98+
</label>
99+
<input class="nhsuk-input nhsuk-date-input__input nhsuk-input--width-2 @dayErrorClass" id="day" name="day" type="number" value="@contractReviewDay">
100+
</div>
101+
</div>
102+
<div class="nhsuk-date-input__item">
103+
<div class="nhsuk-form-group">
104+
<label class="nhsuk-label nhsuk-date-input__label" for="month">
105+
Month
106+
</label>
107+
<input class="nhsuk-input nhsuk-date-input__input nhsuk-input--width-2 @monthErrorClass" id="month" name="month" type="number" value="@ContractReviewMonth">
108+
</div>
109+
</div>
110+
<div class="nhsuk-date-input__item">
111+
<div class="nhsuk-form-group">
112+
<label class="nhsuk-label nhsuk-date-input__label" for="year">
113+
Year
114+
</label>
115+
<input class="nhsuk-input nhsuk-date-input__input nhsuk-input--width-4 @yearErrorClass" id="year" name="year" type="number" value="@ContractReviewYear">
116+
</div>
117+
</div>
118+
</div>
62119

120+
</fieldset>
63121
</div>
64122
</div>
65123
<button class="nhsuk-button" type="submit">

DigitalLearningSolutions.Web/Views/SuperAdmin/Centres/ManageCentre.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
<b>Contract review date</b>
196196
</dt>
197197
<dd class="nhsuk-summary-list__value">
198-
@Model.ContractReviewDate
198+
@string.Format("{0:dd/MM/yyyy}",@Model.ContractReviewDate)
199199
</dd>
200200
</div>
201201
</dl>

0 commit comments

Comments
 (0)