Skip to content

Instantly share code, notes, and snippets.

View benjaminvanrenterghem's full-sized avatar
🟢

Benjamin Van Renterghem benjaminvanrenterghem

🟢
View GitHub Profile
@benjaminvanrenterghem
benjaminvanrenterghem / ValidationBehavior_Cancellation_Snippet.cs
Created September 17, 2022 00:15
ValidationBehavior Cancellation Snippet
// ...
// #1 Indien het aantal validatiefouten groter is dan 0 dan retourneert de ValidationBehavior zelf een Response
// en worden latere Behaviors en de Handler niet bereikt
if (failures.Count > 0) {
var result = new TResponse();
result.Messages = failures.Select(f =>
new Message {
Body = f.ErrorMessage,
// [i] Bestand terug te vinden onder project Logic.Behaviors
// #1 De interface IPipelineBehavior wordt geimplementeerd (de Handle functie ontwikkelen wordt verplicht)
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
// #2 Net zoals in ValidationBehavior verduidelijken we onze generieke type parameters door middel van where
// Argument 1 is de IRequest zoals we vooraf gezien hebben in hoofdstuk 2.3 (CQRS)
// Argument 2 definieert dat we een Response object gaan retourneren, deze bevat de Content property
// tesamen met andere properties die betrekking houden tot de uitkomst van ons verzoek, eventuele foutmeldingen, etc
where TRequest : IRequest<TResponse>
// #1 De Request, definieert als doel het bekomen van een Response<StageProfileResponseDTO> bij afhandeling
public class UpdateStageProfileCommand : IRequest<Response<StageProfileResponseDTO>> {
public StageProfileRequestDTO ProfileRequestDTO { get; set; }
public ParsedJwtToken ParsedJwtToken { get; set; }
}
// #2 De Request Handler, maakt gebruik van bovenstaande Request en definieert hetzelfde doel
public class UpdateStageProfileCommandHandler : IRequestHandler<UpdateStageProfileCommand, Response<StageProfileResponseDTO>> {
// #3 Om met de databank te interageren wordt gebruik gemaakt van generieke repositories
public int VoegBestuurderToe(Bestuurder bestuurder) {
if(bestuurder is null) {
throw new BestuurderManagerException("Meegegeven bestuurder is null.");
} else if(bestuurder.Id is not null || bestuurder.Id > 0) {
throw new BestuurderManagerException("Id van bestuurder is reeds ingesteld.");
} else if(this.ZoekBestuurders("Rijksregisternummer", bestuurder.RijksRegisterNummer).Count > 0) {
throw new BestuurderManagerException("Er bestaat reeds een bestuurder met dit RRN.");
}
// Afhankelijkheid #1
@benjaminvanrenterghem
benjaminvanrenterghem / ServiceCollectionExtentions.cs
Created September 8, 2022 13:55 — forked from GetoXs/ServiceCollectionExtentions.cs
Register All Types (with Generic) in .NET Core DependencyInjection
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
public static class ServiceCollectionExtentions
{
public static void AddAllTypes<T>(this IServiceCollection services
, Assembly[] assemblies
, bool additionalRegisterTypesByThemself = false
@benjaminvanrenterghem
benjaminvanrenterghem / admin_creds.sql
Created July 22, 2022 20:01
Demo_user_credentials______ASP_NET_API_Tutorial
USE BVRNET;
INSERT INTO [BVRNET].[dbo].[User] (DisplayName, LoginName, Email, Password, ClearanceLevels, Deleted, CreatedDate, UpdatedDate)
VALUES ('u1d', 'u1login', 'user@test.com', '04b7bcd583850fa5fe5ad6a9109e7a93db5d7a8330ba815041b1afdda8bf1ea3', 'User', 0, GETDATE(), GETDATE()),
('u2d', 'u2login', 'admin@test.com', '951351844714e596b29aa9c894bdb6e17f441fbcd77760c4596c59c64ac47222', 'User,Management', 0, GETDATE(), GETDATE());
@benjaminvanrenterghem
benjaminvanrenterghem / prerequest_postman.js
Last active July 22, 2022 19:58
Custom_Postman_PreRequest_Script____ASP_NET_API_Tutorial
let jwtFetchError = "Failed to gather JWT Token - check if your API is running, select a Postman Environment -- and make sure to have added the 2 default accounts (query can be found in prerequest script -or- in the documentation)";
if(JSON.parse(pm.environment.get("LOGIN_WITHOUT_AUTH"))){
console.log("No JWT Token was fetched due to the selected Postman Environment");
return;
}
pm.sendRequest({
rejectUnauthorized: false,
url: pm.environment.get("API_HTTP_PROTOCOL") +
@benjaminvanrenterghem
benjaminvanrenterghem / postman-pre-request.js
Created July 1, 2022 21:41 — forked from bcnzer/postman-pre-request.js
Postman pre-request script to automatically get a bearer token from Auth0 and save it for reuse
const echoPostRequest = {
url: 'https://<my url>.auth0.com/oauth/token',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'application/json',
raw: JSON.stringify(
{
client_id:'<your client ID>',
client_secret:'<your client secret>',
pm.sendRequest({
url: 'https://login.microsoftonline.com/' + pm.environment.get("tenantId") + '/oauth2/token',
method: 'POST',
header: 'Content-Type: application/x-www-form-urlencoded',
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "client_credentials", disabled: false},
{key: "client_id", value: pm.environment.get("clientId"), disabled: false},
{key: "client_secret", value: pm.environment.get("clientSecret"), disabled: false},

Step 1 - Make a Discord Webhook

  1. Find the Discord channel in which you would like to send commits and other updates

  2. In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe! WebhookDiscord

Step 2 - Set up the webhook on Github

  1. Navigate to your repository on Github, and open the Settings Settings