From 72ee725bc57f6719ecad52be5d7b8d29f8857899 Mon Sep 17 00:00:00 2001 From: volkanceylan Date: Sat, 4 Jan 2025 20:05:10 +0300 Subject: [PATCH] Use primary constructor, use ArgumentNullException.ThrowIfNull --- .../RequestHandlers/LanguageDeleteHandler.cs | 10 ++--- .../RequestHandlers/LanguageListHandler.cs | 9 ++--- .../LanguageRetrieveHandler.cs | 11 ++---- .../RequestHandlers/LanguageSaveHandler.cs | 11 ++---- .../Role/RequestHandlers/RoleDeleteHandler.cs | 11 ++---- .../Role/RequestHandlers/RoleListHandler.cs | 9 ++--- .../RequestHandlers/RoleRetrieveHandler.cs | 9 ++--- .../Role/RequestHandlers/RoleSaveHandler.cs | 11 ++---- .../Modules/Administration/Role/RoleHelper.cs | 6 +-- .../RolePermissionRepository.cs | 21 +++------- .../Translation/TranslationEndpoint.cs | 17 +++----- .../Translation/TranslationRepository.cs | 18 +++------ .../Modules/Administration/User/LoggingRow.cs | 7 +--- .../User/RequestHandlers/UserDeleteHandler.cs | 16 +++----- .../User/RequestHandlers/UserListHandler.cs | 9 ++--- .../RequestHandlers/UserRetrieveHandler.cs | 11 ++---- .../User/RequestHandlers/UserSaveHandler.cs | 14 +++---- .../UserPermissionRepository.cs | 16 ++------ .../UserRole/UserRoleRepository.cs | 15 ++----- .../Modules/Common/Dashboard/DashboardPage.cs | 6 +-- .../Navigation/NavigationModelFactory.cs | 39 +++++++------------ .../Modules/Membership/Account/AccountPage.cs | 20 +++------- 22 files changed, 95 insertions(+), 201 deletions(-) diff --git a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageDeleteHandler.cs b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageDeleteHandler.cs index c63ff38761..5b6f44a455 100644 --- a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageDeleteHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageDeleteHandler.cs @@ -1,16 +1,12 @@ -using MyRow = Serene.Administration.LanguageRow; +using MyRow = Serene.Administration.LanguageRow; using MyRequest = Serenity.Services.DeleteRequest; using MyResponse = Serenity.Services.DeleteResponse; - namespace Serene.Administration; public interface ILanguageDeleteHandler : IDeleteHandler { } -public class LanguageDeleteHandler : DeleteRequestHandler, ILanguageDeleteHandler +public class LanguageDeleteHandler(IRequestContext context) + : DeleteRequestHandler(context), ILanguageDeleteHandler { - public LanguageDeleteHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageListHandler.cs b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageListHandler.cs index b86587c79e..45c65f25b2 100644 --- a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageListHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageListHandler.cs @@ -1,4 +1,4 @@ -using MyRow = Serene.Administration.LanguageRow; +using MyRow = Serene.Administration.LanguageRow; using MyRequest = Serenity.Services.ListRequest; using MyResponse = Serenity.Services.ListResponse; @@ -7,10 +7,7 @@ namespace Serene.Administration; public interface ILanguageListHandler : IListHandler { } -public class LanguageListHandler : ListRequestHandler, ILanguageListHandler +public class LanguageListHandler(IRequestContext context) + : ListRequestHandler(context), ILanguageListHandler { - public LanguageListHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageRetrieveHandler.cs b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageRetrieveHandler.cs index 17a7de1299..324f050dd6 100644 --- a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageRetrieveHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageRetrieveHandler.cs @@ -1,15 +1,12 @@ -using MyRow = Serene.Administration.LanguageRow; +using MyRow = Serene.Administration.LanguageRow; using MyRequest = Serenity.Services.RetrieveRequest; using MyResponse = Serenity.Services.RetrieveResponse; - namespace Serene.Administration; public interface ILanguageRetrieveHandler : IRetrieveHandler { } -public class LanguageRetrieveHandler : RetrieveRequestHandler, ILanguageRetrieveHandler + +public class LanguageRetrieveHandler(IRequestContext context) + : RetrieveRequestHandler(context), ILanguageRetrieveHandler { - public LanguageRetrieveHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageSaveHandler.cs b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageSaveHandler.cs index 3868396826..9d60ae4811 100644 --- a/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageSaveHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Language/RequestHandlers/LanguageSaveHandler.cs @@ -1,15 +1,12 @@ -using MyRow = Serene.Administration.LanguageRow; +using MyRow = Serene.Administration.LanguageRow; using MyRequest = Serenity.Services.SaveRequest; using MyResponse = Serenity.Services.SaveResponse; - namespace Serene.Administration; public interface ILanguageSaveHandler : ISaveHandler { } -public class LanguageSaveHandler : SaveRequestHandler, ILanguageSaveHandler + +public class LanguageSaveHandler(IRequestContext context) + : SaveRequestHandler(context), ILanguageSaveHandler { - public LanguageSaveHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleDeleteHandler.cs b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleDeleteHandler.cs index 6293dd3b53..78db5b1dcd 100644 --- a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleDeleteHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleDeleteHandler.cs @@ -1,15 +1,12 @@ -using MyRow = Serene.Administration.RoleRow; +using MyRow = Serene.Administration.RoleRow; using MyRequest = Serenity.Services.DeleteRequest; using MyResponse = Serenity.Services.DeleteResponse; - namespace Serene.Administration; public interface IRoleDeleteHandler : IDeleteHandler { } -public class RoleDeleteHandler : DeleteRequestHandler, IRoleDeleteHandler + +public class RoleDeleteHandler(IRequestContext context) + : DeleteRequestHandler(context), IRoleDeleteHandler { - public RoleDeleteHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleListHandler.cs b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleListHandler.cs index 8f27d786e9..0c14e46eef 100644 --- a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleListHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleListHandler.cs @@ -1,4 +1,4 @@ -using MyRow = Serene.Administration.RoleRow; +using MyRow = Serene.Administration.RoleRow; using MyRequest = Serenity.Services.ListRequest; using MyResponse = Serenity.Services.ListResponse; @@ -7,10 +7,7 @@ namespace Serene.Administration; public interface IRoleListHandler : IListHandler { } -public class RoleListHandler : ListRequestHandler, IRoleListHandler +public class RoleListHandler(IRequestContext context) + : ListRequestHandler(context), IRoleListHandler { - public RoleListHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleRetrieveHandler.cs b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleRetrieveHandler.cs index ae1bdc805a..44f055569e 100644 --- a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleRetrieveHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleRetrieveHandler.cs @@ -1,4 +1,4 @@ -using MyRow = Serene.Administration.RoleRow; +using MyRow = Serene.Administration.RoleRow; using MyRequest = Serenity.Services.RetrieveRequest; using MyResponse = Serenity.Services.RetrieveResponse; @@ -6,10 +6,7 @@ namespace Serene.Administration; public interface IRoleRetrieveHandler : IRetrieveHandler { } -public class RoleRetrieveHandler : RetrieveRequestHandler, IRoleRetrieveHandler +public class RoleRetrieveHandler(IRequestContext context) + : RetrieveRequestHandler(context), IRoleRetrieveHandler { - public RoleRetrieveHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleSaveHandler.cs b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleSaveHandler.cs index 4b7ac99d0c..44e4c65df0 100644 --- a/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleSaveHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/Role/RequestHandlers/RoleSaveHandler.cs @@ -1,17 +1,14 @@ -using MyRow = Serene.Administration.RoleRow; +using MyRow = Serene.Administration.RoleRow; using MyRequest = Serenity.Services.SaveRequest; using MyResponse = Serenity.Services.SaveResponse; namespace Serene.Administration; public interface IRoleSaveHandler : ISaveHandler { } -public class RoleSaveHandler : SaveRequestHandler, IRoleSaveHandler -{ - public RoleSaveHandler(IRequestContext context) - : base(context) - { - } +public class RoleSaveHandler(IRequestContext context) + : SaveRequestHandler(context), IRoleSaveHandler +{ protected override void InvalidateCacheOnCommit() { base.InvalidateCacheOnCommit(); diff --git a/serene/src/Serene.Web/Modules/Administration/Role/RoleHelper.cs b/serene/src/Serene.Web/Modules/Administration/Role/RoleHelper.cs index acc2b23929..f85b9980a5 100644 --- a/serene/src/Serene.Web/Modules/Administration/Role/RoleHelper.cs +++ b/serene/src/Serene.Web/Modules/Administration/Role/RoleHelper.cs @@ -7,14 +7,12 @@ public static class RoleHelper private static MyRow.RowFields Fld { get { return MyRow.Fields; } } public static Dictionary GetRoleById(ITwoLevelCache cache, ISqlConnections sqlConnections) { - if (cache is null) - throw new ArgumentNullException(nameof(cache)); + ArgumentNullException.ThrowIfNull(cache); return cache.GetLocalStoreOnly("RoleById", TimeSpan.Zero, Fld.GenerationKey, () => { - if (sqlConnections is null) - throw new ArgumentNullException(nameof(sqlConnections)); + ArgumentNullException.ThrowIfNull(sqlConnections); using var connection = sqlConnections.NewFor(); return connection.List().ToDictionary(x => x.RoleId.Value); diff --git a/serene/src/Serene.Web/Modules/Administration/RolePermission/RolePermissionRepository.cs b/serene/src/Serene.Web/Modules/Administration/RolePermission/RolePermissionRepository.cs index 034d4538fa..438ed7b8e3 100644 --- a/serene/src/Serene.Web/Modules/Administration/RolePermission/RolePermissionRepository.cs +++ b/serene/src/Serene.Web/Modules/Administration/RolePermission/RolePermissionRepository.cs @@ -3,30 +3,22 @@ namespace Serene.Administration.Repositories; -public class RolePermissionRepository : BaseRepository +public class RolePermissionRepository(IRequestContext context) : BaseRepository(context) { - public RolePermissionRepository(IRequestContext context) - : base(context) - { - } - private static MyRow.RowFields Fld { get { return MyRow.Fields; } } public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); - if (request.RoleID is null) - throw new ArgumentNullException(nameof(request.RoleID)); - if (request.Permissions is null) - throw new ArgumentNullException(nameof(request.Permissions)); + ArgumentNullException.ThrowIfNull(request); + ArgumentNullException.ThrowIfNull(request.RoleID); + ArgumentNullException.ThrowIfNull(request.Permissions); var roleID = request.RoleID.Value; var oldList = new HashSet( GetExisting(uow.Connection, roleID) .Select(x => x.PermissionKey), StringComparer.OrdinalIgnoreCase); - var newList = new HashSet(request.Permissions.ToList(), + var newList = new HashSet([.. request.Permissions], StringComparer.OrdinalIgnoreCase); if (oldList.SetEquals(newList)) @@ -73,8 +65,7 @@ private List GetExisting(IDbConnection connection, int roleId) public RolePermissionListResponse List(IDbConnection connection, RolePermissionListRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (request.RoleID is null) throw new ArgumentNullException(nameof(request.RoleID)); diff --git a/serene/src/Serene.Web/Modules/Administration/Translation/TranslationEndpoint.cs b/serene/src/Serene.Web/Modules/Administration/Translation/TranslationEndpoint.cs index ccddabe50c..fb2c2c1df8 100644 --- a/serene/src/Serene.Web/Modules/Administration/Translation/TranslationEndpoint.cs +++ b/serene/src/Serene.Web/Modules/Administration/Translation/TranslationEndpoint.cs @@ -5,19 +5,12 @@ namespace Serene.Administration.Endpoints; [Route("Services/Administration/Translation/[action]")] [ServiceAuthorize(PermissionKeys.Translation)] -public class TranslationEndpoint : ServiceEndpoint +public class TranslationEndpoint(IWebHostEnvironment hostEnvironment, + ILocalTextRegistry localTextRegistry, ITypeSource typeSource) : ServiceEndpoint { - protected IWebHostEnvironment HostEnvironment { get; } - protected ILocalTextRegistry LocalTextRegistry { get; } - protected ITypeSource TypeSource { get; } - - public TranslationEndpoint(IWebHostEnvironment hostEnvironment, - ILocalTextRegistry localTextRegistry, ITypeSource typeSource) - { - HostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); - LocalTextRegistry = localTextRegistry ?? throw new ArgumentNullException(nameof(localTextRegistry)); - TypeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource)); - } + protected IWebHostEnvironment HostEnvironment { get; } = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); + protected ILocalTextRegistry LocalTextRegistry { get; } = localTextRegistry ?? throw new ArgumentNullException(nameof(localTextRegistry)); + protected ITypeSource TypeSource { get; } = typeSource ?? throw new ArgumentNullException(nameof(typeSource)); private MyRepository NewRepository() { diff --git a/serene/src/Serene.Web/Modules/Administration/Translation/TranslationRepository.cs b/serene/src/Serene.Web/Modules/Administration/Translation/TranslationRepository.cs index 08522be518..304064ed4b 100644 --- a/serene/src/Serene.Web/Modules/Administration/Translation/TranslationRepository.cs +++ b/serene/src/Serene.Web/Modules/Administration/Translation/TranslationRepository.cs @@ -7,20 +7,12 @@ namespace Serene.Administration.Repositories; -public class TranslationRepository : BaseRepository +public class TranslationRepository(IRequestContext context, IWebHostEnvironment hostEnvironment, + ILocalTextRegistry localTextRegistry, ITypeSource typeSource) : BaseRepository(context) { - protected IWebHostEnvironment HostEnvironment { get; } - protected ILocalTextRegistry LocalTextRegistry { get; } - protected ITypeSource TypeSource { get; } - - public TranslationRepository(IRequestContext context, IWebHostEnvironment hostEnvironment, - ILocalTextRegistry localTextRegistry, ITypeSource typeSource) - : base(context) - { - HostEnvironment = hostEnvironment; - LocalTextRegistry = localTextRegistry; - TypeSource = typeSource; - } + protected IWebHostEnvironment HostEnvironment { get; } = hostEnvironment; + protected ILocalTextRegistry LocalTextRegistry { get; } = localTextRegistry; + protected ITypeSource TypeSource { get; } = typeSource; public static string GetUserTextsFilePath(IWebHostEnvironment hostEnvironment, string languageID) { diff --git a/serene/src/Serene.Web/Modules/Administration/User/LoggingRow.cs b/serene/src/Serene.Web/Modules/Administration/User/LoggingRow.cs index 9767970fd4..f9435011f5 100644 --- a/serene/src/Serene.Web/Modules/Administration/User/LoggingRow.cs +++ b/serene/src/Serene.Web/Modules/Administration/User/LoggingRow.cs @@ -31,15 +31,10 @@ protected LoggingRow() : base() { } DateTimeField IUpdateLogRow.UpdateDateField => fields.UpdateDate; } -public class LoggingRowFields : RowFieldsBase +public class LoggingRowFields(string tableName = null, string fieldPrefix = null) : RowFieldsBase(tableName, fieldPrefix) { public Int32Field InsertUserId; public DateTimeField InsertDate; public Int32Field UpdateUserId; public DateTimeField UpdateDate; - - public LoggingRowFields(string tableName = null, string fieldPrefix = null) - : base(tableName, fieldPrefix) - { - } } diff --git a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserDeleteHandler.cs b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserDeleteHandler.cs index c2c73e9340..d16536d1eb 100644 --- a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserDeleteHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserDeleteHandler.cs @@ -1,22 +1,18 @@ -using Serenity.Extensions.Entities; +using Serenity.Extensions.Entities; using System.Data; -using MyRow = Serene.Administration.UserRow; using MyRequest = Serenity.Services.DeleteRequest; using MyResponse = Serenity.Services.DeleteResponse; +using MyRow = Serene.Administration.UserRow; namespace Serene.Administration; public interface IUserDeleteHandler : IDeleteHandler { } -public class UserDeleteHandler : DeleteRequestHandler, IUserDeleteHandler -{ - private readonly IOptions environmentOptions; - public UserDeleteHandler(IRequestContext context, IOptions environmentOptions) - : base(context) - { - this.environmentOptions = environmentOptions ?? +public class UserDeleteHandler(IRequestContext context, IOptions environmentOptions) + : DeleteRequestHandler(context), IUserDeleteHandler +{ + private readonly IOptions environmentOptions = environmentOptions ?? throw new System.ArgumentNullException(nameof(environmentOptions)); - } protected override void ValidateRequest() { diff --git a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserListHandler.cs b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserListHandler.cs index 7e40eec88a..9f288947d8 100644 --- a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserListHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserListHandler.cs @@ -1,4 +1,4 @@ -using MyRow = Serene.Administration.UserRow; +using MyRow = Serene.Administration.UserRow; using MyRequest = Serene.Administration.UserListRequest; using MyResponse = Serenity.Services.ListResponse; @@ -6,10 +6,7 @@ namespace Serene.Administration; public interface IUserListHandler : IListHandler { } -public class UserListHandler : ListRequestHandler, IUserListHandler +public class UserListHandler(IRequestContext context) + : ListRequestHandler(context), IUserListHandler { - public UserListHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserRetrieveHandler.cs b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserRetrieveHandler.cs index b57bb4e78c..f0ed75d183 100644 --- a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserRetrieveHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserRetrieveHandler.cs @@ -1,15 +1,12 @@ -using MyRow = Serene.Administration.UserRow; +using MyRow = Serene.Administration.UserRow; using MyRequest = Serenity.Services.RetrieveRequest; using MyResponse = Serenity.Services.RetrieveResponse; - namespace Serene.Administration; public interface IUserRetrieveHandler : IRetrieveHandler { } -public class UserRetrieveHandler : RetrieveRequestHandler, IUserRetrieveHandler + +public class UserRetrieveHandler(IRequestContext context) + : RetrieveRequestHandler(context), IUserRetrieveHandler { - public UserRetrieveHandler(IRequestContext context) - : base(context) - { - } } \ No newline at end of file diff --git a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserSaveHandler.cs b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserSaveHandler.cs index 98d90a9c69..3d3aabf0a9 100644 --- a/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserSaveHandler.cs +++ b/serene/src/Serene.Web/Modules/Administration/User/RequestHandlers/UserSaveHandler.cs @@ -5,19 +5,15 @@ namespace Serene.Administration; public interface IUserSaveHandler : ISaveHandler { } -public class UserSaveHandler : SaveRequestHandler, IUserSaveHandler + +public class UserSaveHandler(IRequestContext context, IOptions environmentOptions) + : SaveRequestHandler(context), IUserSaveHandler { private static MyRow.RowFields Fld { get { return MyRow.Fields; } } - public UserSaveHandler(IRequestContext context, IOptions environmentOptions) - : base(context) - { - this.environmentOptions = environmentOptions ?? - throw new System.ArgumentNullException(nameof(environmentOptions)); - } - private string password; - private readonly IOptions environmentOptions; + private readonly IOptions environmentOptions = environmentOptions ?? + throw new ArgumentNullException(nameof(environmentOptions)); protected override void GetEditableFields(HashSet editable) { diff --git a/serene/src/Serene.Web/Modules/Administration/UserPermission/UserPermissionRepository.cs b/serene/src/Serene.Web/Modules/Administration/UserPermission/UserPermissionRepository.cs index bf5c33ec68..4f8e3d59e1 100644 --- a/serene/src/Serene.Web/Modules/Administration/UserPermission/UserPermissionRepository.cs +++ b/serene/src/Serene.Web/Modules/Administration/UserPermission/UserPermissionRepository.cs @@ -4,19 +4,13 @@ namespace Serene.Administration.Repositories; -public class UserPermissionRepository : BaseRepository +public class UserPermissionRepository(IRequestContext context) : BaseRepository(context) { - public UserPermissionRepository(IRequestContext context) - : base(context) - { - } - private static MyRow.RowFields Fld { get { return MyRow.Fields; } } public SaveResponse Update(IUnitOfWork uow, UserPermissionUpdateRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (request.UserID is null) throw new ArgumentNullException(nameof(request.UserID)); if (request.Permissions is null) @@ -85,8 +79,7 @@ private static List GetExisting(IDbConnection connection, int userId) public ListResponse List(IDbConnection connection, UserPermissionListRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (request.UserID is null) throw new ArgumentNullException(nameof(request.UserID)); @@ -100,8 +93,7 @@ public ListResponse List(IDbConnection connection, UserPermissionListRequ public ListResponse ListRolePermissions(IDbConnection connection, UserPermissionListRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (request.UserID is null) throw new ArgumentNullException(nameof(request.UserID)); diff --git a/serene/src/Serene.Web/Modules/Administration/UserRole/UserRoleRepository.cs b/serene/src/Serene.Web/Modules/Administration/UserRole/UserRoleRepository.cs index acfd4fd532..69f80c207e 100644 --- a/serene/src/Serene.Web/Modules/Administration/UserRole/UserRoleRepository.cs +++ b/serene/src/Serene.Web/Modules/Administration/UserRole/UserRoleRepository.cs @@ -3,19 +3,13 @@ namespace Serene.Administration.Repositories; -public class UserRoleRepository : BaseRepository +public class UserRoleRepository(IRequestContext context) : BaseRepository(context) { - public UserRoleRepository(IRequestContext context) - : base(context) - { - } - private static MyRow.RowFields Fld { get { return MyRow.Fields; } } public SaveResponse Update(IUnitOfWork uow, UserRoleUpdateRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (request.UserID is null) throw new ArgumentNullException(nameof(request.UserID)); if (request.Roles is null) @@ -26,7 +20,7 @@ public SaveResponse Update(IUnitOfWork uow, UserRoleUpdateRequest request) GetExisting(uow.Connection, userID) .Select(x => x.RoleId.Value)); - var newList = new HashSet(request.Roles.ToList()); + var newList = new HashSet([.. request.Roles]); if (oldList.SetEquals(newList)) return new SaveResponse(); @@ -72,8 +66,7 @@ private List GetExisting(IDbConnection connection, int userId) public UserRoleListResponse List(IDbConnection connection, UserRoleListRequest request) { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (request.UserID is null) throw new ArgumentNullException(nameof(request.UserID)); diff --git a/serene/src/Serene.Web/Modules/Common/Dashboard/DashboardPage.cs b/serene/src/Serene.Web/Modules/Common/Dashboard/DashboardPage.cs index 5555b28970..55e5be1f8a 100644 --- a/serene/src/Serene.Web/Modules/Common/Dashboard/DashboardPage.cs +++ b/serene/src/Serene.Web/Modules/Common/Dashboard/DashboardPage.cs @@ -10,11 +10,9 @@ public class DashboardPage : Controller #if (Northwind) public ActionResult Index([FromServices] ITwoLevelCache cache, [FromServices] ISqlConnections sqlConnections) { - if (cache is null) - throw new System.ArgumentNullException(nameof(cache)); + ArgumentNullException.ThrowIfNull(cache); - if (sqlConnections is null) - throw new System.ArgumentNullException(nameof(sqlConnections)); + ArgumentNullException.ThrowIfNull(sqlConnections); var o = Serenity.Demo.Northwind.OrderRow.Fields; diff --git a/serene/src/Serene.Web/Modules/Common/Navigation/NavigationModelFactory.cs b/serene/src/Serene.Web/Modules/Common/Navigation/NavigationModelFactory.cs index 16a9c3dc34..a35011ce94 100644 --- a/serene/src/Serene.Web/Modules/Common/Navigation/NavigationModelFactory.cs +++ b/serene/src/Serene.Web/Modules/Common/Navigation/NavigationModelFactory.cs @@ -4,30 +4,20 @@ namespace Serene.AppServices; -public class NavigationModelFactory : INavigationModelFactory +public class NavigationModelFactory( + ITwoLevelCache cache, + IHttpContextAccessor httpContextAccessor, + IPermissionService permissions, + IServiceProvider serviceProvider, + ITypeSource typeSource, + IUserAccessor userAccessor) : INavigationModelFactory { - private readonly ITwoLevelCache cache; - private readonly IHttpContextAccessor httpContextAccessor; - private readonly IPermissionService permissions; - private readonly IServiceProvider serviceProvider; - private readonly ITypeSource typeSource; - private readonly IUserAccessor userAccessor; - - public NavigationModelFactory( - ITwoLevelCache cache, - IHttpContextAccessor httpContextAccessor, - IPermissionService permissions, - IServiceProvider serviceProvider, - ITypeSource typeSource, - IUserAccessor userAccessor) - { - this.httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); - this.cache = cache ?? throw new ArgumentNullException(nameof(cache)); - this.permissions = permissions ?? throw new ArgumentNullException(nameof(permissions)); - this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); - this.typeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource)); - this.userAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor)); - } + private readonly ITwoLevelCache cache = cache ?? throw new ArgumentNullException(nameof(cache)); + private readonly IHttpContextAccessor httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); + private readonly IPermissionService permissions = permissions ?? throw new ArgumentNullException(nameof(permissions)); + private readonly IServiceProvider serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); + private readonly ITypeSource typeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource)); + private readonly IUserAccessor userAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor)); private string ToAbsolute(string url) { @@ -83,8 +73,7 @@ private void CalcActivePath(NavigationModel model) private void SearchActivePath(NavigationItem link, string currentUrl, ref string bestMatch, ref int bestMatchLength, ref NavigationItem bestLink) { - if (link == null) - throw new ArgumentNullException(nameof(link)); + ArgumentNullException.ThrowIfNull(link); var url = link.Url; diff --git a/serene/src/Serene.Web/Modules/Membership/Account/AccountPage.cs b/serene/src/Serene.Web/Modules/Membership/Account/AccountPage.cs index 7dfc05393e..850490f5f8 100644 --- a/serene/src/Serene.Web/Modules/Membership/Account/AccountPage.cs +++ b/serene/src/Serene.Web/Modules/Membership/Account/AccountPage.cs @@ -6,15 +6,10 @@ namespace Serene.Membership.Pages; [Route("Account/[action]")] -public partial class AccountPage : Controller +public partial class AccountPage(ITwoLevelCache cache, ITextLocalizer localizer) : Controller { - protected ITwoLevelCache Cache { get; } - protected ITextLocalizer Localizer { get; } - public AccountPage(ITwoLevelCache cache, ITextLocalizer localizer) - { - Localizer = localizer ?? throw new ArgumentNullException(nameof(localizer)); - Cache = cache ?? throw new ArgumentNullException(nameof(cache)); - } + protected ITwoLevelCache Cache { get; } = cache ?? throw new ArgumentNullException(nameof(cache)); + protected ITextLocalizer Localizer { get; } = localizer ?? throw new ArgumentNullException(nameof(localizer)); [HttpGet] public ActionResult Login(int? denied, string activated, string returnUrl) @@ -44,17 +39,14 @@ public Result Login(LoginRequest request, return this.ExecuteMethod(() => { - if (request is null) - throw new ArgumentNullException(nameof(request)); + ArgumentNullException.ThrowIfNull(request); if (string.IsNullOrEmpty(request.Username)) throw new ArgumentNullException(nameof(request.Username)); - if (passwordValidator is null) - throw new ArgumentNullException(nameof(passwordValidator)); + ArgumentNullException.ThrowIfNull(passwordValidator); - if (userClaimCreator is null) - throw new ArgumentNullException(nameof(userClaimCreator)); + ArgumentNullException.ThrowIfNull(userClaimCreator); var username = request.Username; var result = passwordValidator.Validate(ref username, request.Password);