File tree Expand file tree Collapse file tree
src/SchoolAccount.Web.Mvc Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using GovUk . Frontend . AspNetCore ;
22using SchoolAccount . Web . Mvc . Authentication . Extensions ;
3+ using SchoolAccount . Web . Mvc . Features . Header ;
34using SchoolAccount . Web . Mvc . Infrastructure ;
45
56namespace SchoolAccount . Web . Mvc ;
@@ -16,6 +17,7 @@ IConfigurationManager configuration
1617 services . AddDsiAuthentication ( configuration ) ;
1718 services . AddControllersWithFeatureViews ( ) ;
1819 services . AddGovUkFrontend ( ) ;
20+ services . AddScoped < IHeaderContentProvider , HeaderContentProvider > ( ) ;
1921
2022 if ( env . IsDevelopment ( ) )
2123 {
Original file line number Diff line number Diff line change 1+ using SchoolAccount . SharedKernel ;
2+
3+ namespace SchoolAccount . Web . Mvc . Features . Header ;
4+
5+ public interface IHeaderContentProvider
6+ {
7+ bool IsAuthenticated { get ; }
8+ string ? OrganisationName { get ; }
9+ }
10+
11+ public class HeaderContentProvider : IHeaderContentProvider
12+ {
13+ public bool IsAuthenticated { get ; }
14+ public string ? OrganisationName { get ; }
15+
16+ public HeaderContentProvider ( IUserContext userContext )
17+ {
18+ IsAuthenticated = userContext . IsAuthenticated ;
19+ OrganisationName = userContext . Organisation ? . Name ;
20+ }
21+ }
Original file line number Diff line number Diff line change 1- @using SchoolAccount .SharedKernel
2- @inject IUserContext CurrentUser
1+ @using SchoolAccount .Web . Mvc . Features . Header
2+ @inject IHeaderContentProvider HeaderContentProvider
33
44@* ReSharper disable Razor.LayoutNotResolved *@
55@* ReSharper disable Razor.SectionNotResolved *@
66
77@{
88 Layout = " _GovUkPageTemplate" ;
9-
10- var isAuthenticated = CurrentUser ? .IsAuthenticated == true ;
11- var organisationName = CurrentUser ? .Organisation ? .Name ;
129}
1310
1411@section Head {
2623 </a >
2724 </div >
2825 <div class =" header-navigation" >
29- @if (isAuthenticated )
26+ @if (HeaderContentProvider . IsAuthenticated )
3027 {
31- <span class =" header-navigation__school" >@organisationName </span >
28+ <span class =" header-navigation__school" >@HeaderContentProvider.OrganisationName </span >
3229
3330 @using (Html .BeginForm (" Logout" , " Account" , FormMethod .Post ))
3431 {
You can’t perform that action at this time.
0 commit comments