Skip to content

Instantly share code, notes, and snippets.

View sgbj's full-sized avatar
🧙‍♂️

Scott Batary sgbj

🧙‍♂️
View GitHub Profile
@sgbj
sgbj / Program.cs
Created February 19, 2021 18:19
Middleware
// Based on ASP.NET Core's ConnectionBuilder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
var pipeline = new Pipeline()
.Use((context, next) =>
{
public static class DbExtensions
{
public static IDbCommand CreateCommand(this IDbConnection connection, FormattableString sql)
{
var command = connection.CreateCommand();
var substitutions = new object[sql.ArgumentCount];
for (var i = 0; i < sql.ArgumentCount; i++)
{
var parameter = command.CreateParameter();
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Todo.Data;
using Todo.Models;
namespace Todo.Pages
@page
@using System.Linq
@using Todo.Pages
@model IndexModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<form method="POST">
<button asp-page-handler="create"></button>
</form>
public async Task<IActionResult> OnPostCreateAsync()
{
...
}
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Todo.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
}
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Todo.Data;
namespace Todo
{
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
using Microsoft.EntityFrameworkCore;
using Todo.Models;
namespace Todo.Data
{
public class TodoDbContext : DbContext
{
public TodoDbContext(DbContextOptions<TodoDbContext> options) : base(options)
{
}
namespace Todo.Models
{
public class TodoItem
{
public int Id { get; set; }
public string Description { get; set; }
public bool IsCompleted { get; set; }
}
}