Skip to content

Commit 658f085

Browse files
committed
TD-3922-Controller refactor -DataService reference removed from the controller. Code modified to use service class methods.
1 parent 8813e05 commit 658f085

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Centre/Dashboard/ContractDetailsController.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre.Dashboard
22
{
3-
using DigitalLearningSolutions.Data.DataServices;
4-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
53
using DigitalLearningSolutions.Data.Enums;
64
using DigitalLearningSolutions.Web.Attributes;
75
using DigitalLearningSolutions.Web.Helpers;
86
using DigitalLearningSolutions.Web.Models.Enums;
7+
using DigitalLearningSolutions.Web.Services;
98
using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.ContractDetails;
109
using Microsoft.AspNetCore.Authorization;
1110
using Microsoft.AspNetCore.Mvc;
@@ -18,27 +17,27 @@
1817
[Route("/TrackingSystem/Centre/ContractDetails")]
1918
public class ContractDetailsController : Controller
2019
{
21-
private readonly ICentresDataService centresDataService;
22-
private readonly ICourseDataService courseDataService;
23-
private readonly IUserDataService userDataService;
20+
private readonly ICentresService centresService;
21+
private readonly ICourseService courseService;
22+
private readonly IUserService userService;
2423

2524
public ContractDetailsController(
26-
ICentresDataService centresDataService,
27-
IUserDataService userDataService,
28-
ICourseDataService courseDataService
25+
ICentresService centresService,
26+
IUserService userService,
27+
ICourseService courseService
2928
)
3029
{
31-
this.centresDataService = centresDataService;
32-
this.userDataService = userDataService;
33-
this.courseDataService = courseDataService;
30+
this.centresService = centresService;
31+
this.userService = userService;
32+
this.courseService = courseService;
3433
}
3534

3635
public IActionResult Index()
3736
{
3837
var centreId = User.GetCentreIdKnownNotNull();
39-
var centreDetails = centresDataService.GetCentreDetailsById(centreId)!;
40-
var adminUsersAtCentre = userDataService.GetAdminUsersByCentreId(centreId);
41-
var numberOfCourses = courseDataService.GetNumberOfActiveCoursesAtCentreFilteredByCategory(centreId, null);
38+
var centreDetails = centresService.GetCentreDetailsById(centreId)!;
39+
var adminUsersAtCentre = userService.GetAdminUsersByCentreId(centreId);
40+
var numberOfCourses = courseService.GetNumberOfActiveCoursesAtCentreFilteredByCategory(centreId, null);
4241

4342
var model = new ContractDetailsViewModel(adminUsersAtCentre, centreDetails, numberOfCourses);
4443

DigitalLearningSolutions.Web/Services/CentresService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void UpdateCentreManagerDetails(
4343
string? GetCentreName(int centreId);
4444
IEnumerable<(int, string)> GetCentresForDelegateSelfRegistrationAlphabetical();
4545
(bool autoRegistered, string? autoRegisterManagerEmail) GetCentreAutoRegisterValues(int centreId);
46+
Centre? GetCentreDetailsById(int centreId);
4647
}
4748

4849
public class CentresService : ICentresService
@@ -148,5 +149,10 @@ public void UpdateCentreManagerDetails(int centreId, string firstName, string la
148149
{
149150
return centresDataService.GetCentreAutoRegisterValues(centreId);
150151
}
152+
153+
public Centre? GetCentreDetailsById(int centreId)
154+
{
155+
return centresDataService.GetCentreDetailsById(centreId);
156+
}
151157
}
152158
}

DigitalLearningSolutions.Web/Services/CourseService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ int diagCompletionThreshold
130130
IEnumerable<CompletedCourse> GetCompletedCourses(int candidateId);
131131
IEnumerable<AvailableCourse> GetAvailableCourses(int candidateId, int? centreId);
132132
void EnrolOnSelfAssessment(int selfAssessmentId, int delegateUserId, int centreId);
133+
int GetNumberOfActiveCoursesAtCentreFilteredByCategory(int centreId, int? categoryId);
133134
}
134135

135136
public class CourseService : ICourseService
@@ -607,5 +608,10 @@ public void EnrolOnSelfAssessment(int selfAssessmentId, int delegateUserId, int
607608
{
608609
courseDataService.EnrolSelfAssessment(selfAssessmentId, delegateUserId, centreId);
609610
}
611+
612+
public int GetNumberOfActiveCoursesAtCentreFilteredByCategory(int centreId, int? categoryId)
613+
{
614+
return courseDataService.GetNumberOfActiveCoursesAtCentreFilteredByCategory(centreId, categoryId);
615+
}
610616
}
611617
}

DigitalLearningSolutions.Web/Services/UserService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ string registrationConfirmationHash
143143
AdminUser? GetAdminUserByEmailAddress(string emailAddress);
144144
DelegateAccount? GetDelegateAccountById(int id);
145145
int? GetUserIdFromUsername(string username);
146+
List<AdminUser> GetAdminUsersByCentreId(int centreId);
146147
}
147148

148149
public class UserService : IUserService
@@ -791,5 +792,10 @@ public bool CentreSpecificEmailIsInUseAtCentre(string email, int centreId)
791792
{
792793
return userDataService.GetUserIdFromUsername(username);
793794
}
795+
796+
public List<AdminUser> GetAdminUsersByCentreId(int centreId)
797+
{
798+
return userDataService.GetAdminUsersByCentreId(centreId);
799+
}
794800
}
795801
}

0 commit comments

Comments
 (0)