Skip to content

Commit 41ed709

Browse files
TD-988: 1. Issue when Date field is filled 0 has been resolved.
2. Dropdown value issue resolved 3. Not accepting current date issue resolved
1 parent 5f8ada4 commit 41ed709

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
@@ -450,7 +450,7 @@ public IActionResult AddCentre(AddCentreSuperAdminViewModel model)
450450
[HttpGet]
451451
[NoCaching]
452452
[Route("SuperAdmin/Centres/{centreId=0:int}/EditContractInfo")]
453-
public IActionResult EditContractInfo(int centreId , int? day, int? month, int? year)
453+
public IActionResult EditContractInfo(int centreId, int? day, int? month, int? year, int? ContractTypeID, long? ServerSpaceBytesInc, long? DelegateUploadSpace)
454454
{
455455
ContractInfo centre = this.centresDataService.GetContractInfo(centreId);
456456
var contractTypes = this.contractTypesDataService.GetContractTypes().ToList();
@@ -460,15 +460,15 @@ public IActionResult EditContractInfo(int centreId , int? day, int? month, int?
460460
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
461461
centre.ContractTypeID, centre.ContractType,
462462
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
463-
centre.ContractReviewDate,day,month,year);
463+
centre.ContractReviewDate, day, month, year);
464464
model.ServerSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
465-
serverspace, centre.ServerSpaceBytesInc
465+
serverspace, ServerSpaceBytesInc ?? centre.ServerSpaceBytesInc
466466
);
467-
model.PerDelegateUploadSpaceOptions= SelectListHelper.MapLongOptionsToSelectListItems(
468-
delegatespace, centre.DelegateUploadSpace
467+
model.PerDelegateUploadSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
468+
delegatespace, DelegateUploadSpace ?? centre.DelegateUploadSpace
469469
);
470-
model.ContractTypeOptions= SelectListHelper.MapOptionsToSelectListItems(
471-
contractTypes, centre.ContractTypeID
470+
model.ContractTypeOptions = SelectListHelper.MapOptionsToSelectListItems(
471+
contractTypes, ContractTypeID ?? centre.ContractTypeID
472472
);
473473
if (day != null && month != null && year != null)
474474
{
@@ -480,20 +480,38 @@ public IActionResult EditContractInfo(int centreId , int? day, int? month, int?
480480

481481
[Route("SuperAdmin/Centres/{centreId=0:int}/EditContractInfo")]
482482
[HttpPost]
483-
public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewModel,int? day,int? month,int? year)
483+
public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewModel, int? day, int? month, int? year)
484484
{
485-
if (day != 0 | month != 0 | year != 0)
485+
if ((day != 0 && day != null) | (month != 0 && month != null) | (year != 0 && year != null))
486486
{
487-
var validationResult = OldDateValidator.ValidateDate(day??0, month??0, year??0);
487+
var validationResult = OldDateValidator.ValidateDate(day ?? 0, month ?? 0, year ?? 0);
488+
if(day!=null&&month!=null&&year!=null)
489+
{
490+
var today = new DateTime(year ?? 0, month ?? 0, day ?? 0);
491+
if (today == DateTime.Now.Date)
492+
{
493+
validationResult.DateValid = true;
494+
validationResult.ErrorMessage = "";
495+
}
496+
}
488497
if (!validationResult.DateValid)
489498
{
490499
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 });
500+
if (month == null) month = 0;
501+
if (year == null) year = 0;
502+
return RedirectToAction("EditContractInfo", new
503+
{
504+
contractTypeViewModel.CentreId,
505+
day,
506+
month,
507+
year,
508+
contractTypeViewModel.ContractTypeID,
509+
contractTypeViewModel.ServerSpaceBytesInc,
510+
contractTypeViewModel.DelegateUploadSpace
511+
});
494512
}
495513
}
496-
if (!ModelState.IsValid)
514+
if (!ModelState.IsValid)
497515
{
498516
ContractInfo centre = this.centresDataService.GetContractInfo(contractTypeViewModel.CentreId);
499517
var contractTypes = this.contractTypesDataService.GetContractTypes().ToList();
@@ -503,7 +521,7 @@ public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewMode
503521
var model = new ContractTypeViewModel(centre.CentreID, centre.CentreName,
504522
centre.ContractTypeID, centre.ContractType,
505523
centre.ServerSpaceBytesInc, centre.DelegateUploadSpace,
506-
centre.ContractReviewDate, day,month,year);
524+
centre.ContractReviewDate, day, month, year);
507525
model.ServerSpaceOptions = SelectListHelper.MapLongOptionsToSelectListItems(
508526
serverspace, model.ServerSpaceBytesInc
509527
);
@@ -516,7 +534,7 @@ public IActionResult EditContractInfo(ContractTypeViewModel contractTypeViewMode
516534
return View(model);
517535
}
518536
DateTime? date = null;
519-
if(day!=null&&month!=null&year!=null)
537+
if ((day != 0 && day != null) && (month != 0 && month != null) && (year != 0 && year != null))
520538
{
521539
date = new DateTime(year ?? 0, month ?? 0, day ?? 0);
522540
}

0 commit comments

Comments
 (0)