diff --git a/src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs b/src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs index 92312ef1..d338531d 100644 --- a/src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs +++ b/src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs @@ -26,10 +26,8 @@ public ValueTask> GetAllAsync( Expression> orderBy = null, bool descending = true, int page = 1, - int pageSize = int.MaxValue) - { - return GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize); - } + int pageSize = int.MaxValue) => + GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize); public ValueTask> GetAllByProjectionAsync( Expression> selector, diff --git a/src/LinkDotNet.Blog.Infrastructure/Persistence/RavenDb/Repository.cs b/src/LinkDotNet.Blog.Infrastructure/Persistence/RavenDb/Repository.cs index f81343fe..b104689e 100644 --- a/src/LinkDotNet.Blog.Infrastructure/Persistence/RavenDb/Repository.cs +++ b/src/LinkDotNet.Blog.Infrastructure/Persistence/RavenDb/Repository.cs @@ -39,15 +39,13 @@ public async ValueTask GetByIdAsync(string id) return await session.LoadAsync(id); } - public async ValueTask> GetAllAsync( + public ValueTask> GetAllAsync( Expression> filter = null, Expression> orderBy = null, bool descending = true, int page = 1, - int pageSize = int.MaxValue) - { - return await GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize); - } + int pageSize = int.MaxValue) => + GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize); public async ValueTask> GetAllByProjectionAsync( Expression> selector, diff --git a/src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Repository.cs b/src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Repository.cs index c26cdec0..a584bc0f 100644 --- a/src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Repository.cs +++ b/src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Repository.cs @@ -42,15 +42,13 @@ public async ValueTask GetByIdAsync(string id) return await blogDbContext.Set().SingleOrDefaultAsync(b => b.Id == id); } - public async ValueTask> GetAllAsync( + public ValueTask> GetAllAsync( Expression> filter = null, Expression> orderBy = null, bool descending = true, int page = 1, - int pageSize = int.MaxValue) - { - return await GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize); - } + int pageSize = int.MaxValue) => + GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize); public async ValueTask> GetAllByProjectionAsync( Expression> selector, diff --git a/src/LinkDotNet.Blog.Web/Authentication/OpenIdConnect/AuthExtensions.cs b/src/LinkDotNet.Blog.Web/Authentication/OpenIdConnect/AuthExtensions.cs index 9effe606..9d931fe0 100644 --- a/src/LinkDotNet.Blog.Web/Authentication/OpenIdConnect/AuthExtensions.cs +++ b/src/LinkDotNet.Blog.Web/Authentication/OpenIdConnect/AuthExtensions.cs @@ -13,7 +13,7 @@ public static class AuthExtensions { public static void UseAuthentication(this IServiceCollection services) { - var authInformation = services.BuildServiceProvider().GetService>(); + var authInformation = services.BuildServiceProvider().GetRequiredService>(); services.Configure(options => { diff --git a/src/LinkDotNet.Blog.Web/Controller/RssFeedController.cs b/src/LinkDotNet.Blog.Web/Controller/RssFeedController.cs index b24fad14..082d3994 100644 --- a/src/LinkDotNet.Blog.Web/Controller/RssFeedController.cs +++ b/src/LinkDotNet.Blog.Web/Controller/RssFeedController.cs @@ -96,7 +96,7 @@ private static SyndicationItem CreateSyndicationItemFromBlogPost(string url, Blo private static void AddCategories(Collection categories, BlogPostRssInfo blogPost) { - foreach (var tag in blogPost.Tags ?? Array.Empty()) + foreach (var tag in blogPost.Tags ?? []) { categories.Add(new SyndicationCategory(tag)); } diff --git a/src/LinkDotNet.Blog.Web/DatabaseHealthCheck.cs b/src/LinkDotNet.Blog.Web/DatabaseHealthCheck.cs index 3500fba1..dae34838 100644 --- a/src/LinkDotNet.Blog.Web/DatabaseHealthCheck.cs +++ b/src/LinkDotNet.Blog.Web/DatabaseHealthCheck.cs @@ -17,6 +17,6 @@ public DatabaseHealthCheck(IRepository repository) public Task CheckHealthAsync( HealthCheckContext context, - CancellationToken cancellationToken = default) => + CancellationToken cancellationToken = default) => repository.PerformHealthCheckAsync().AsTask(); } diff --git a/src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/FutureDateValidationAttribute.cs b/src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/FutureDateValidationAttribute.cs index 14cebecb..ff979822 100644 --- a/src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/FutureDateValidationAttribute.cs +++ b/src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/FutureDateValidationAttribute.cs @@ -8,13 +8,8 @@ public sealed class FutureDateValidationAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { - if (value is null) - { - return ValidationResult.Success; - } - - return (DateTime)value <= DateTime.UtcNow - ? new ValidationResult("The scheduled publish date must be in the future.") - : ValidationResult.Success; + return value is not DateTime dt || dt > DateTime.UtcNow + ? ValidationResult.Success + : new ValidationResult("The scheduled publish date must be in the future."); } } diff --git a/src/LinkDotNet.Blog.Web/Features/Components/SelectionRange.cs b/src/LinkDotNet.Blog.Web/Features/Components/SelectionRange.cs index 0ab56255..70ccc2dc 100644 --- a/src/LinkDotNet.Blog.Web/Features/Components/SelectionRange.cs +++ b/src/LinkDotNet.Blog.Web/Features/Components/SelectionRange.cs @@ -1,6 +1,6 @@ namespace LinkDotNet.Blog.Web.Features.Components; -public record struct SelectionRange +public readonly record struct SelectionRange { public int Start { get; init; }