Skip to content

Commit 88fffde

Browse files
authored
Merge pull request #360 from Bram1903/Code_Refactoring
Thank you very much for your participation
2 parents 39bd782 + ece2081 commit 88fffde

File tree

242 files changed

+1723
-2119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+1723
-2119
lines changed

src/Application/Common/Behaviours/AuthorizationBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using CleanArchitecture.Blazor.Application.Common.ExceptionHandlers;
45
using CleanArchitecture.Blazor.Application.Common.Interfaces.Identity;
56
using CleanArchitecture.Blazor.Application.Common.Security;
6-
using System.Reflection;
77

88
namespace CleanArchitecture.Blazor.Application.Common.Behaviours;
99

src/Application/Common/Behaviours/CacheInvalidationBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ILogger<CacheInvalidationBehaviour<TRequest, TResponse>> logger
2020
}
2121
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
2222
{
23-
_logger.LogTrace("{Name} cache expire with {@Request}.", nameof(request), request);
23+
_logger.LogTrace("{Name} cache expire with {@Request}", nameof(request), request);
2424
var response = await next().ConfigureAwait(false);
2525
if (!string.IsNullOrEmpty(request.CacheKey))
2626
{

src/Application/Common/Behaviours/MemoryCacheBehaviour.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using LazyCache;
5-
64
namespace CleanArchitecture.Blazor.Application.Common.Behaviours;
75

86
public class MemoryCacheBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
@@ -21,7 +19,7 @@ ILogger<MemoryCacheBehaviour<TRequest, TResponse>> logger
2119
}
2220
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
2321
{
24-
_logger.LogTrace("{Name} is caching with {@Request}.", nameof(request),request);
22+
_logger.LogTrace("{Name} is caching with {@Request}", nameof(request),request);
2523
var response = await _cache.GetOrAddAsync(
2624
request.CacheKey,
2725
async () =>

src/Application/Common/Behaviours/UnhandledExceptionBehaviour.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Threading;
5-
64
namespace CleanArchitecture.Blazor.Application.Common.Behaviours;
75

86
public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>

src/Application/Common/Behaviours/ValidationBehaviour.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public ValidationBehaviour(
1717
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
1818
{
1919
var context = new ValidationContext<TRequest>(request);
20-
var failrules = _validators
20+
var failRules = _validators
2121
.Select(validator => validator.Validate(context))
2222
.SelectMany(result => result.Errors)
23-
.Where(failrules => failrules != null)
23+
.Where(failRules => failRules != null)
2424
.ToList();
25-
if (failrules.Any())
25+
if (failRules.Any())
2626
{
27-
throw new ValidationException(failrules);
27+
throw new ValidationException(failRules);
2828
}
2929
return await next().ConfigureAwait(false);
3030
}

src/Application/Common/Configurations/AppConfigurationSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace CleanArchitecture.Blazor.Application.Configurations;
4+
namespace CleanArchitecture.Blazor.Application.Common.Configurations;
55

66
public class AppConfigurationSettings
77
{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace CleanArchitecture.Blazor.Application.Configurations;
4+
namespace CleanArchitecture.Blazor.Application.Common.Configurations;
55

66
public class DashboardSettings
77
{
88
public const string SectionName = nameof(DashboardSettings);
99

10-
public string Version { get; set; }="6.0.2";
10+
public string Version { get; set; } = "6.0.2";
1111
public string App { get; set; } = "Dashboard";
1212
public string AppName { get; set; } = "Admin Dashboard";
1313
public string AppFlavor { get; set; } = String.Empty;
1414
public string AppFlavorSubscript { get; set; } = String.Empty;
1515
public string Company { get; set; } = "Company";
16-
public string Copyright { get; set; } = "@2022 Copyright";
16+
public string Copyright { get; set; } = "@2023 Copyright";
1717

1818
}

src/Application/Common/ExceptionHandlers/ConflictException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace CleanArchitecture.Blazor.Application.Common.Exceptions;
1+
namespace CleanArchitecture.Blazor.Application.Common.ExceptionHandlers;
22
public class ConflictException : ServerException
33
{
44
public ConflictException(string message)
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Net.NetworkInformation;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using CleanArchitecture.Blazor.Application.Features.Products.Commands.AddEdit;
8-
using Microsoft.Data.SqlClient;
9-
using Microsoft.EntityFrameworkCore;
1+
using Microsoft.Data.SqlClient;
102

113
namespace CleanArchitecture.Blazor.Application.Common.ExceptionHandlers;
12-
public class DbExceptionHandler<TRequest, TResponse, TException> : IRequestExceptionHandler<TRequest, TResponse, TException>
4+
5+
public class
6+
DbExceptionHandler<TRequest, TResponse, TException> : IRequestExceptionHandler<TRequest, TResponse, TException>
137
where TRequest : IRequest<Result>
148
where TException : DbUpdateException
159
{
@@ -20,51 +14,53 @@ public DbExceptionHandler(ILogger<DbExceptionHandler<TRequest, TResponse, TExcep
2014
_logger = logger;
2115
}
2216

23-
public Task Handle(TRequest request, TException exception, RequestExceptionHandlerState<TResponse> state, CancellationToken cancellationToken)
17+
public Task Handle(TRequest request, TException exception, RequestExceptionHandlerState<TResponse> state,
18+
CancellationToken cancellationToken)
2419
{
25-
var response = Activator.CreateInstance<TResponse>();
20+
TResponse response = Activator.CreateInstance<TResponse>();
2621
if (response is Result result)
2722
{
2823
result.Succeeded = false;
29-
result.Errors = getErrors(exception);
24+
result.Errors = GetErrors(exception);
3025
state.SetHandled(response);
3126
}
27+
3228
return Task.CompletedTask;
3329
}
3430

35-
private string[] getErrors(DbUpdateException exception)
31+
private static string[] GetErrors(DbUpdateException exception)
3632
{
3733
IList<string> errors = new List<string>();
3834
if (exception.InnerException != null
39-
&& exception.InnerException != null
40-
&& exception.InnerException is SqlException sqlException
41-
)
35+
&& exception.InnerException != null
36+
&& exception.InnerException is SqlException sqlException
37+
)
4238
{
4339
switch (sqlException.Number)
4440
{
45-
case 2627: // Unique constraint error
46-
errors.Add("A Unique Constraint Error Has Occured While Updating the record! Duplicate Record cannot be inserted in the System.");
41+
case 2627: // Unique constraint error
42+
errors.Add(
43+
"A Unique Constraint Error Has Occured While Updating the record! Duplicate Record cannot be inserted in the System.");
4744
break;
48-
case 544: // Cannot insert explicit value for identity column in table 'Departments' when IDENTITY_INSERT is set to OFF
49-
errors.Add("Cannot insert explicit value for identity column in the system when the id is set to OFF");
45+
case 544
46+
: // Cannot insert explicit value for identity column in table 'Departments' when IDENTITY_INSERT is set to OFF
47+
errors.Add(
48+
"Cannot insert explicit value for identity column in the system when the id is set to OFF");
5049
break;
51-
case 547: // Constraint check violation, Conflict in the database
50+
case 547: // Constraint check violation, Conflict in the database
5251
errors.Add("A Constraint Check violation Error Has Occured While Updating the record(s)!");
5352
break;
54-
case 2601: // Duplicated key row error // Constraint violation exception // A custom exception of yours for concurrency issues
53+
case 2601
54+
: // Duplicated key row error // Constraint violation exception // A custom exception of yours for concurrency issues
5555
errors.Add("A Duplicate Key Error Has Occured While Updating the record(s)!");
5656
break;
57-
case 201: // Proceudre missing parameters
57+
case 201: // Procedure missing parameters
5858
errors.Add("A Missing Parameter has led to Error While Creating the record(s)!");
5959
break;
60-
default:
61-
break;
6260
}
6361
}
6462

6563

66-
6764
return errors.ToArray();
68-
6965
}
70-
}
66+
}

src/Application/Common/ExceptionHandlers/ForbiddenAccessException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace CleanArchitecture.Blazor.Application.Common.Exceptions;
4+
namespace CleanArchitecture.Blazor.Application.Common.ExceptionHandlers;
55

66
public class ForbiddenException : ServerException
77
{

0 commit comments

Comments
 (0)