Instantly share code, notes, and snippets.

View FluentValidationConditionalcheck.cs
RuleFor(x => x.FastDelivery)
.NotEmpty()
.WithState(x => new ValidationState() {
Code = "FastDelivery.empty",
Keys = { ValidationKeys.Delivery }
});
RuleFor(x => x.DeliveryDate)
.NotEmpty()
.WithState(x => new ValidationState()
View AddRedisBackplane.cs
services.AddSignalR()
.AddRedis(configuration["Data:Redis"]);
View MediaTypeHeader.cs
var json = JsonConvert.SerializeObject(body);
var content = new StringContent(json);
content.Headers.ContentType= new MediaTypeHeaderValue("application/json");
return _client.PostAsync(requestUri, content);
View CORS.cs
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
View SignalRClientAfter.ts
this.connection = new HubConnectionBuilder()
.withUrl(url,HttpTransportType.WebSockets)
.build();
View SignalrClientBefore.ts
this.connection = new HubConnection(url, {
transport: TransportType.WebSockets
});
View SignalRRemoveAfter.cs
var userConnectionId = await _userLogic.GetConnectionId(userId);
if (!string.IsNullOrWhiteSpace(userConnectionId))
await Groups.RemoveFromGroupAsync(userConnectionId, groupName);
View SignalRRemoveBefore.cs
var userConnectionId = await _userLogic.GetConnectionId(userId);
if (!string.IsNullOrWhiteSpace(userConnectionId))
await Groups.RemoveAsync(userConnectionId, groupName);
View SignalRGroupAfter.cs
chatResult.Users
.Where(x => !string.IsNullOrWhiteSpace(x.ConnectionId))
.ToList()
.ForEach(async user => { await _chatHub.Groups.AddToGroupAsync(user.ConnectionId, chatId); });
View SignalRGroupBefore.cs
chatResult.Users
.Where(x => !string.IsNullOrWhiteSpace(x.ConnectionId))
.ToList()
.ForEach(async user => { await _chatHub.Groups.AddAsync(user.ConnectionId, chatId); });