Skip to content

Instantly share code, notes, and snippets.

View JuergenGutsch's full-sized avatar
🏠
Working from home

Juergen Gutsch JuergenGutsch

🏠
Working from home
View GitHub Profile
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFramework.Design
dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore
dotnet add package Microsoft.AspNetCore.Identity.UI
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet aspnet-codegenerator identity -dc AuthSample.Data.ApplicationDbContext --files "Account.Register" -sqlite
using System.ComponentModel;
using System.Reflection;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace TagHelperSample.TagHelpers;
public class DataGridTagHelper : TagHelper
{
[HtmlAttributeName("Items")]
public IEnumerable<object> Items { get; set; }
public class PersonGridTagHelper : TagHelper
{
[HtmlAttributeName("persons")]
public IEnumerable<Person> Persons { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "table";
output.Attributes.Add("class", "table");
output.Content.AppendHtml("<tr>");
persons=Id,FirstName,LastName,Age,EmailAddress,Address,City,Phone
43,Patrick,Verstraete,58,[email protected],"680 Strauss Street ",Ontario,(633) 495-7238
78,Isabel,Wright,3,[email protected],"6323 Park Avenue ",Colwood,(462) 445-5772
52,Leslie,MacKenzie,61,[email protected],"2456 Estate Road ",Yorba Linda,(594) 719-6189
65,Alexandra,Kelly,44,[email protected],"8188 Burnett Street ",Whitney,(497) 600-6435
47,Anthony,Hayes,56,[email protected],"6455 Monroe Street ",Pacifica,(241) 771-1426
26,Alyssa,Griffin,19,[email protected],"5674 Bay 16th Street ",Sebastian,(244) 588-1031
81,Claire,Patterson,38,[email protected],"2276 Paerdegat 2nd Street ",Garfield,(609) 242-5209
77,Colby,Baker,24,[email protected],"5036 St Nicholas Avenue ",Cookville,(651) 694-1091
86,Rebecca,Murphy,83,[email protected],"5487 11th Avenue ",Soledad,(303) 243-1134
public class PersonsCsvBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// Specify a default argument name if none is set by ModelBinderAttribute
namespace RoutingSample;
public static class MapMyHealthChecksExtensions
{
public static IEndpointConventionBuilder MapMyHealthChecks(
this IEndpointRouteBuilder endpoints, string pattern = "/myhealth")
{
var pipeline = endpoints
.CreateApplicationBuilder()
.UseMiddleware<MyHealthChecksMiddleware>()
.Build();
namespace RoutingSample;
public class MyHealthChecksMiddleware
{
private readonly ILogger<MyHealthChecksMiddleware> _logger;
public MyHealthChecksMiddleware(
RequestDelegate next,
ILogger<MyHealthChecksMiddleware> logger)
{
namespace HostedServiceSample;
public class SampleBackgroundService : BackgroundService
{
private readonly ILogger<SampleHostedService> logger;
public SampleBackgroundService(ILogger<SampleHostedService> logger)
{
this.logger = logger;
}
using System.Globalization;
using System.Text;
using CsvHelper;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
using OutputFormatterSample.Models;
namespace OutputFormatterSample;
public class CsvOutputFormatter : TextOutputFormatter
using System.Text;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
using OutputFormatterSample.Models;
namespace OutputFormatterSample;
public class VcardOutputFormatter : TextOutputFormatter
{
public string ContentType { get; } = "text/vcard";