This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BusinessValidationPipeline<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | |
where TResponse : class | |
where TRequest : IValidateable | |
{ | |
private readonly IValidator<TRequest> _compositeValidator; | |
private readonly ILogger<TRequest> _logger; | |
private readonly ICurrentUser _currentUser; | |
private readonly IActionContextAccessor _actionContextAccessor; | |
public BusinessValidationPipeline( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
[Route("[action]")] | |
public async Task<IActionResult> CreateUser([FromBody]CreateUserDto userDto) | |
{ | |
var result = await _mediator.Send(new CreateNewUserCommand {CreateUserDto = userDto}); | |
return result.IsValidResponse | |
? CreatedAtRoute(routeValues: new | |
{ | |
controller = "User", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateNewUserCommand : IRequest<ValidateableResponse<ApiResponse<int>>>, IValidateable | |
{ | |
public CreateUserDto CreateUserDto { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateNewUserCommandHandler : IRequestHandler<CreateNewUserCommand, ValidateableResponse<ApiResponse<int>>> | |
{ | |
private readonly ILogger _logger; | |
public CreateNewUserCommandHandler(ILogger logger) | |
{ | |
_logger = logger; | |
} | |
public async Task<ValidateableResponse<ApiResponse<int>>> Handle(CreateNewUserCommand request, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateUserValidator: AbstractValidator<CreateUserDto> | |
{ | |
public CreateUserValidator() | |
{ | |
RuleFor(m => m.Password).NotEmpty(); | |
RuleFor(m => m.UserName).NotEmpty(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidateableResponse | |
{ | |
private readonly IList<string> _errorMessages; | |
public ValidateableResponse(IList<string> errors = null) | |
{ | |
_errorMessages = errors ?? new List<string>(); | |
} | |
public bool IsValidResponse => !_errorMessages.Any(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
del /s /ah /f *.suo | |
del /s /f *.user | |
del /s /f *.cache | |
del /s /f *.keep | |
del /s /ah StyleCop.Cache | |
rd /s /q bin obj .vs ClientBin _Resharper.* _Upgrade* TestResults | |
del dirs.txt | |
dir /s /b /ad bin > dirs.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$file = "consolidated-script.txt" | |
$filenew = "consolidated-script.sql" | |
cat *.sql | sc consolidated-script.txt | |
Rename-Item $file $filenew |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-Package -ProjectName "YourProjectName" | Uninstall-Package -ProjectName "YourProjectName" -RemoveDependencies | |
## Add -Force flag on the end to overcome dependancy issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ViewDataDictionary<T> CreateViewDataDictionary<T>(this HttpContext httpContext, T model) | |
{ | |
var modelMetadataProvider = httpContext.ApplicationServices.GetRequiredService<IModelMetadataProvider>(); | |
return new ViewDataDictionary<T>(modelMetadataProvider, new ModelStateDictionary()) | |
{ | |
Model = model | |
}; | |
} |