Skip to content

Commit 404f52d

Browse files
committed
Added query for CentreApplications table insert
1 parent 4ecc260 commit 404f52d

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

DigitalLearningSolutions.Data/DataServices/CentresDataService.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
namespace DigitalLearningSolutions.Data.DataServices
22
{
33
using Dapper;
4+
using DigitalLearningSolutions.Data.Extensions;
45
using DigitalLearningSolutions.Data.Models.Centres;
56
using DigitalLearningSolutions.Data.Models.DbModels;
67
using Microsoft.Extensions.Logging;
78
using System;
89
using System.Collections.Generic;
910
using System.Data;
11+
using System.Transactions;
1012

1113
public interface ICentresDataService
1214
{
@@ -73,7 +75,8 @@ public int AddCentreForSuperAdmin(
7375
int? regionId,
7476
string? registrationEmail,
7577
string? ipPrefix,
76-
bool showOnMap
78+
bool showOnMap,
79+
bool AddITSPcourses
7780
);
7881

7982
public void UpdateCentreDetailsForSuperAdmin(
@@ -471,10 +474,15 @@ public int AddCentreForSuperAdmin(
471474
int? regionId,
472475
string? registrationEmail,
473476
string? ipPrefix,
474-
bool showOnMap
477+
bool showOnMap,
478+
bool AddITSPcourses
475479
)
476480
{
477-
return connection.QuerySingle<int>(
481+
int newCentreId;
482+
connection.EnsureOpen();
483+
using var transaction = connection.BeginTransaction();
484+
{
485+
newCentreId = connection.QuerySingle<int>(
478486
@"Insert INTO Centres
479487
(CentreName,
480488
ContactForename,
@@ -513,8 +521,25 @@ OUTPUT Inserted.CentreID
513521
registrationEmail,
514522
ipPrefix,
515523
showOnMap
516-
}
524+
},
525+
transaction
517526
);
527+
if (AddITSPcourses)
528+
{
529+
connection.Execute(
530+
@"INSERT INTO [CentreApplications] ([CentreID], [ApplicationID])
531+
SELECT @newCentreId, ApplicationID
532+
FROM Applications
533+
WHERE (Debug = 0) AND (ArchivedDate IS NULL) AND (ASPMenu = 1) AND (CoreContent = 1) AND (BrandID = 1) AND (LaunchedAssess = 1)",
534+
new { newCentreId },
535+
transaction
536+
);
537+
}
538+
539+
transaction.Commit();
540+
return newCentreId;
541+
}
542+
518543
}
519544

520545
public (string firstName, string lastName, string email) GetCentreManagerDetails(int centreId)

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -382,40 +382,25 @@ public IActionResult EditCentreRoleLimits(CentreRoleLimitsViewModel model)
382382
public IActionResult AddCentre()
383383
{
384384
var regions = regionDataService.GetRegionsAlphabetical().ToList();
385-
386385
var centreTypes = this.centresDataService.GetCentreTypes().ToList();
387386

388-
389-
ViewBag.Regions = SelectListHelper.MapOptionsToSelectListItems(regions);
390-
ViewBag.CentreTypes = SelectListHelper.MapOptionsToSelectListItems(centreTypes);
391-
392387
var addCentreSuperAdminViewModel = new AddCentreSuperAdminViewModel();
393388
addCentreSuperAdminViewModel.IpPrefix = "194.176.105";
394389

395390
addCentreSuperAdminViewModel.RegionNameOptions = SelectListHelper.MapOptionsToSelectListItems(regions);
396391
addCentreSuperAdminViewModel.CentreTypeOptions = SelectListHelper.MapOptionsToSelectListItems(centreTypes);
397392

398-
399393
return View(addCentreSuperAdminViewModel);
400394
}
401395

402396
[HttpPost]
403397
[Route("SuperAdmin/Centres/AddCentre")]
404398
public IActionResult AddCentre(AddCentreSuperAdminViewModel model)
405399
{
406-
var centreTypes = this.centresDataService.GetCentreTypes().ToList();
407-
var regions = regionDataService.GetRegionsAlphabetical().ToList();
408-
409400
if (!ModelState.IsValid)
410401
{
411-
//ViewBag.Regions = SelectListHelper.MapOptionsToSelectListItems(
412-
// regions);
413-
//ViewBag.CentreTypes = SelectListHelper.MapOptionsToSelectListItems(
414-
// centreTypes);
415-
ViewBag.Regions = SelectListHelper.MapOptionsToSelectListItems(
416-
regions);
417-
ViewBag.CentreTypes = SelectListHelper.MapOptionsToSelectListItems(
418-
centreTypes);
402+
var centreTypes = this.centresDataService.GetCentreTypes().ToList();
403+
var regions = regionDataService.GetRegionsAlphabetical().ToList();
419404
model.RegionNameOptions = SelectListHelper.MapOptionsToSelectListItems(regions);
420405
model.CentreTypeOptions = SelectListHelper.MapOptionsToSelectListItems(centreTypes);
421406
return View(model);
@@ -431,8 +416,10 @@ public IActionResult AddCentre(AddCentreSuperAdminViewModel model)
431416
model.RegionId,
432417
model.RegistrationEmail,
433418
model.IpPrefix,
434-
model.ShowOnMap
419+
model.ShowOnMap,
420+
model.AddITSPcourses
435421
);
422+
436423
return RedirectToAction("ManageCentre", "Centres", new { centreId = insertedID });
437424
}
438425
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ public AddCentreSuperAdminViewModel(Centre centre)
5555
public string? ContactLastName { get; set; }
5656
public string? ContactEmail { get; set; }
5757
public string? ContactPhone { get; set; }
58+
59+
[MaxLength(250, ErrorMessage = "Email must be 250 characters or fewer")]
60+
[EmailAddress(ErrorMessage = "Enter an email in the correct format, like [email protected]")]
61+
[NoWhitespace(ErrorMessage = "Email must not contain any whitespace characters")]
5862
public string? RegistrationEmail { get; set; }
63+
5964
public bool AddITSPcourses { get; set; }
6065

6166
public IEnumerable<SelectListItem> CentreTypeOptions { get; set; } = new List<SelectListItem>();

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
}
88
@if (errorHasOccurred)
99
{
10-
<vc:error-summary order-of-property-names="@(new [] { nameof(Model.CentreName), nameof(Model.CentreTypeId), nameof(Model.RegionId) })" />
10+
<vc:error-summary order-of-property-names="@(new [] { nameof(Model.CentreName), nameof(Model.ContactEmail), nameof(Model.CentreTypeId), nameof(Model.RegionId), nameof(Model.RegistrationEmail) })" />
1111
}
1212
<div id="form-group">
1313
<form method="post" asp-action="AddCentre">
14-
@* @Html.HiddenFor(x=>x.CentreType)
15-
@Html.HiddenFor(x=>x.RegionName)*@
1614
<div>
1715
<h1 id="form-heading" class="nhsuk-fieldset__heading nhsuk-label--l">
1816
Add new centre
@@ -99,7 +97,6 @@
9997
css-class="nhsuk-u-width-full"
10098
default-option="Select a centre type"
10199
select-list-options="Model.CentreTypeOptions" />
102-
@*select-list-options="@ViewBag.CentreTypes" />*@
103100
</div>
104101
</div>
105102

@@ -113,8 +110,6 @@
113110
css-class="nhsuk-u-width-full"
114111
default-option="Select a region"
115112
select-list-options="Model.RegionNameOptions" />
116-
@*select-list-options="@ViewBag.Regions" />*@
117-
118113
</div>
119114
</div>
120115

0 commit comments

Comments
 (0)