Skip to content

Commit 76536eb

Browse files
authored
Merge pull request #2089 from TechnologyEnhancedLearning/Develop/Features/TD-988-Super-Admin-Centres-Edit-centre-contract-information-page_
TD-988: Issue when Date field is filled 0 has been resolved
2 parents da6f68b + 41ed709 commit 76536eb

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
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,28,8,2023);
224+
var result = controller.EditContractInfo(centreId,28,8,2023,10024,10024,100024);
225225

226226
// Then
227227
using (new AssertionScope())

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

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public IActionResult AddCentre(AddCentreSuperAdminViewModel model)
447447
[HttpGet]
448448
[NoCaching]
449449
[Route("SuperAdmin/Centres/{centreId=0:int}/EditContractInfo")]
450-
public IActionResult EditContractInfo(int centreId , int? day, int? month, int? year)
450+
public IActionResult EditContractInfo(int centreId, int? day, int? month, int? year, int? ContractTypeID, long? ServerSpaceBytesInc, long? DelegateUploadSpace)
451451
{
452452
ContractInfo centre = this.centresDataService.GetContractInfo(centreId);
453453
var contractTypes = this.contractTypesDataService.GetContractTypes().ToList();
@@ -457,15 +457,15 @@ public IActionResult EditContractInfo(int centreId , int? day, int? month, int?
457457
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
458458
centre.ContractTypeID, centre.ContractType,
459459
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
460-
centre.ContractReviewDate,day,month,year);
460+
centre.ContractReviewDate, day, month, year);
461461
model.ServerSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
462-
serverspace, centre.ServerSpaceBytesInc
462+
serverspace, ServerSpaceBytesInc ?? centre.ServerSpaceBytesInc
463463
);
464-
model.PerDelegateUploadSpaceOptions= SelectListHelper.MapLongOptionsToSelectListItems(
465-
delegatespace, centre.DelegateUploadSpace
464+
model.PerDelegateUploadSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
465+
delegatespace, DelegateUploadSpace ?? centre.DelegateUploadSpace
466466
);
467-
model.ContractTypeOptions= SelectListHelper.MapOptionsToSelectListItems(
468-
contractTypes, centre.ContractTypeID
467+
model.ContractTypeOptions = SelectListHelper.MapOptionsToSelectListItems(
468+
contractTypes, ContractTypeID ?? centre.ContractTypeID
469469
);
470470
if (day != null && month != null && year != null)
471471
{
@@ -477,20 +477,38 @@ public IActionResult EditContractInfo(int centreId , int? day, int? month, int?
477477

478478
[Route("SuperAdmin/Centres/{centreId=0:int}/EditContractInfo")]
479479
[HttpPost]
480-
public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewModel,int? day,int? month,int? year)
480+
public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewModel, int? day, int? month, int? year)
481481
{
482-
if (day != 0 | month != 0 | year != 0)
482+
if ((day != 0 && day != null) | (month != 0 && month != null) | (year != 0 && year != null))
483483
{
484-
var validationResult = OldDateValidator.ValidateDate(day??0, month??0, year??0);
484+
var validationResult = OldDateValidator.ValidateDate(day ?? 0, month ?? 0, year ?? 0);
485+
if(day!=null&&month!=null&&year!=null)
486+
{
487+
var today = new DateTime(year ?? 0, month ?? 0, day ?? 0);
488+
if (today == DateTime.Now.Date)
489+
{
490+
validationResult.DateValid = true;
491+
validationResult.ErrorMessage = "";
492+
}
493+
}
485494
if (!validationResult.DateValid)
486495
{
487496
if (day == null) day = 0;
488-
if(month == null) month = 0;
489-
if (year == null) year= 0;
490-
return RedirectToAction("EditContractInfo", new { contractTypeViewModel.CentreId, day, month, year });
497+
if (month == null) month = 0;
498+
if (year == null) year = 0;
499+
return RedirectToAction("EditContractInfo", new
500+
{
501+
contractTypeViewModel.CentreId,
502+
day,
503+
month,
504+
year,
505+
contractTypeViewModel.ContractTypeID,
506+
contractTypeViewModel.ServerSpaceBytesInc,
507+
contractTypeViewModel.DelegateUploadSpace
508+
});
491509
}
492510
}
493-
if (!ModelState.IsValid)
511+
if (!ModelState.IsValid)
494512
{
495513
ContractInfo centre = this.centresDataService.GetContractInfo(contractTypeViewModel.CentreId);
496514
var contractTypes = this.contractTypesDataService.GetContractTypes().ToList();
@@ -500,7 +518,7 @@ public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewMode
500518
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
501519
centre.ContractTypeID, centre.ContractType,
502520
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
503-
centre.ContractReviewDate, day,month,year);
521+
centre.ContractReviewDate, day, month, year);
504522
model.ServerSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
505523
serverspace, model.ServerSpaceBytesInc
506524
);
@@ -513,7 +531,7 @@ public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewMode
513531
return View(model);
514532
}
515533
DateTime? date = null;
516-
if(day!=null&&month!=null&year!=null)
534+
if ((day != 0 && day != null) && (month != 0 && month != null) && (year != 0 && year != null))
517535
{
518536
date = new DateTime(year ?? 0, month ?? 0, day ?? 0);
519537
}

0 commit comments

Comments
 (0)