From d5801fa6d8fcfd3d937490a2caa9125142cb4d56 Mon Sep 17 00:00:00 2001
From: JasonWhall <42138928+JasonWhall@users.noreply.github.com>
Date: Wed, 28 Jul 2021 13:37:27 +0100
Subject: [PATCH] Initial commit, add code.
Signed-off-by: JasonWhall <42138928+JasonWhall@users.noreply.github.com>
---
.dockerignore | 25 +
.editorconfig | 88 +++
.gitignore | 579 ++++++++++++++++++
Directory.Build.props | 11 +
README.md | 3 +
TodoApp.Api/Dockerfile | 22 +
.../20210728100004_InitialCreate.Designer.cs | 42 ++
.../20210728100004_InitialCreate.cs | 30 +
.../Migrations/TodoContextModelSnapshot.cs | 40 ++
TodoApp.Api/Program.cs | 82 +++
TodoApp.Api/Properties/launchSettings.json | 38 ++
TodoApp.Api/ResultMapper.cs | 31 +
TodoApp.Api/TodoApp.Api.csproj | 20 +
TodoApp.Api/appsettings.Development.json | 9 +
TodoApp.Api/appsettings.json | 13 +
TodoApp.sln | 33 +
global.json | 6 +
version.json | 10 +
18 files changed, 1082 insertions(+)
create mode 100644 .dockerignore
create mode 100644 .editorconfig
create mode 100644 .gitignore
create mode 100644 Directory.Build.props
create mode 100644 README.md
create mode 100644 TodoApp.Api/Dockerfile
create mode 100644 TodoApp.Api/Migrations/20210728100004_InitialCreate.Designer.cs
create mode 100644 TodoApp.Api/Migrations/20210728100004_InitialCreate.cs
create mode 100644 TodoApp.Api/Migrations/TodoContextModelSnapshot.cs
create mode 100644 TodoApp.Api/Program.cs
create mode 100644 TodoApp.Api/Properties/launchSettings.json
create mode 100644 TodoApp.Api/ResultMapper.cs
create mode 100644 TodoApp.Api/TodoApp.Api.csproj
create mode 100644 TodoApp.Api/appsettings.Development.json
create mode 100644 TodoApp.Api/appsettings.json
create mode 100644 TodoApp.sln
create mode 100644 global.json
create mode 100644 version.json
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..3729ff0
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,25 @@
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
\ No newline at end of file
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..edcc611
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,88 @@
+# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\Jason.whalley\source\repos\TodoApp codebase based on best match to current usage at 27/07/2021
+# You can modify the rules from these initially generated values to suit your own policies
+# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
+[*.cs]
+
+
+#Core editorconfig formatting - indentation
+
+#use soft tabs (spaces) for indentation
+indent_style = space
+
+#Formatting - new line options
+
+#require members of object initializers to be on the same line
+csharp_new_line_before_members_in_object_initializers = false
+#require braces to be on a new line for types and methods (also known as "Allman" style)
+csharp_new_line_before_open_brace = types, methods
+
+#Formatting - organize using options
+
+#do not place System.* using directives before other using directives
+dotnet_sort_system_directives_first = false
+
+#Formatting - spacing options
+
+#require NO space between a cast and the value
+csharp_space_after_cast = false
+#require a space after a keyword in a control flow statement such as a for loop
+csharp_space_after_keywords_in_control_flow_statements = true
+#remove space within empty argument list parentheses
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+#remove space between method call name and opening parenthesis
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
+csharp_space_between_method_call_parameter_list_parentheses = false
+#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
+csharp_space_between_method_declaration_parameter_list_parentheses = false
+
+#Formatting - wrapping options
+
+#leave code block on single line
+csharp_preserve_single_line_blocks = true
+
+#Style - expression bodied member options
+
+#prefer block bodies for constructors
+csharp_style_expression_bodied_constructors = false:suggestion
+#prefer block bodies for methods
+csharp_style_expression_bodied_methods =false:silent
+#prefer expression-bodied members for properties
+csharp_style_expression_bodied_properties = true:suggestion
+
+#Style - Expression-level preferences
+
+#prefer objects to be initialized using object initializers when possible
+dotnet_style_object_initializer = true:suggestion
+
+#Style - implicit and explicit types
+
+#prefer var over explicit type in all cases, unless overridden by another code style rule
+csharp_style_var_elsewhere = true:suggestion
+#prefer var when the type is already mentioned on the right-hand side of a declaration expression
+csharp_style_var_when_type_is_apparent = true:suggestion
+
+#Style - language keyword and framework type options
+
+#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
+dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
+
+#Style - modifier options
+
+#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
+
+#Style - Modifier preferences
+
+#when this rule is set to a list of modifiers, prefer the specified ordering.
+csharp_preferred_modifier_order = public,private,static,readonly:suggestion
+
+#Style - qualification options
+
+#prefer fields not to be prefaced with this. or Me. in Visual Basic
+dotnet_style_qualification_for_field = false:suggestion
+#prefer properties not to be prefaced with this. or Me. in Visual Basic
+dotnet_style_qualification_for_property = false:suggestion
+
+[*.{cs,vb}]
+dotnet_diagnostic.CA1050.severity=silent
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6a20935
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,579 @@
+
+# Created by https://www.toptal.com/developers/gitignore/api/csharp,visualstudiocode,visualstudio
+# Edit at https://www.toptal.com/developers/gitignore?templates=csharp,visualstudiocode,visualstudio
+
+### Csharp ###
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.tlog
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Nuget personal access tokens and Credentials
+nuget.config
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# VS Code files for those working on multiple tools
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
+
+# Windows Installer files from build outputs
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+### VisualStudioCode ###
+
+# Local History for Visual Studio Code
+
+### VisualStudioCode Patch ###
+# Ignore all local history of files
+.history
+.ionide
+
+### VisualStudio ###
+
+# User-specific files
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+
+# Mono auto generated files
+
+# Build results
+
+# Visual Studio 2015/2017 cache/options directory
+# Uncomment if you have tasks that create the project's static files in wwwroot
+
+# Visual Studio 2017 auto generated files
+
+# MSTest test Results
+
+# NUnit
+
+# Build Results of an ATL Project
+
+# Benchmark Results
+
+# .NET Core
+
+# ASP.NET Scaffolding
+
+# StyleCop
+
+# Files built by Visual Studio
+
+# Chutzpah Test files
+
+# Visual C++ cache files
+
+# Visual Studio profiler
+
+# Visual Studio Trace Files
+
+# TFS 2012 Local Workspace
+
+# Guidance Automation Toolkit
+
+# ReSharper is a .NET coding add-in
+
+# TeamCity is a build add-in
+
+# DotCover is a Code Coverage Tool
+
+# AxoCover is a Code Coverage Tool
+
+# Coverlet is a free, cross platform Code Coverage Tool
+
+# Visual Studio code coverage results
+
+# NCrunch
+
+# MightyMoose
+
+# Web workbench (sass)
+
+# Installshield output folder
+
+# DocProject is a documentation generator add-in
+
+# Click-Once directory
+
+# Publish Web Output
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+
+# NuGet Packages
+# NuGet Symbol Packages
+# The packages folder can be ignored because of Package Restore
+# except build/, which is used as an MSBuild target.
+# Uncomment if necessary however generally it will be regenerated when needed
+# NuGet v3's project.json files produces more ignorable files
+
+# Nuget personal access tokens and Credentials
+
+# Microsoft Azure Build Output
+
+# Microsoft Azure Emulator
+
+# Windows Store app package directories and files
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+# but keep track of directories ending in .cache
+
+# Others
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+
+# RIA/Silverlight projects
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+
+# SQL Server files
+
+# Business Intelligence projects
+
+# Microsoft Fakes
+
+# GhostDoc plugin setting file
+
+# Node.js Tools for Visual Studio
+
+# Visual Studio 6 build log
+
+# Visual Studio 6 workspace options file
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+
+# Visual Studio LightSwitch build output
+
+# Paket dependency manager
+
+# FAKE - F# Make
+
+# CodeRush personal settings
+
+# Python Tools for Visual Studio (PTVS)
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+
+# Telerik's JustMock configuration file
+
+# BizTalk build output
+
+# OpenCover UI analysis results
+
+# Azure Stream Analytics local run output
+
+# MSBuild Binary and Structured Log
+
+# NVidia Nsight GPU debugger configuration file
+
+# MFractors (Xamarin productivity tool) working folder
+
+# Local History for Visual Studio
+
+# BeatPulse healthcheck temp database
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+
+# Ionide (cross platform F# VS Code tools) working folder
+
+# Fody - auto-generated XML schema
+
+# VS Code files for those working on multiple tools
+
+# Local History for Visual Studio Code
+
+# Windows Installer files from build outputs
+
+# JetBrains Rider
+
+### VisualStudio Patch ###
+# Additional files built by Visual Studio
+
+# End of https://www.toptal.com/developers/gitignore/api/csharp,visualstudiocode,visualstudio
\ No newline at end of file
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..4d5d70a
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,11 @@
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+ $(MSBuildThisFileDirectory)
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..331e8b3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Dotnet 6 Minimal API
+
+A safe playground for trying out dotnet 6 and minimal APIs functionality.
\ No newline at end of file
diff --git a/TodoApp.Api/Dockerfile b/TodoApp.Api/Dockerfile
new file mode 100644
index 0000000..a2443f8
--- /dev/null
+++ b/TodoApp.Api/Dockerfile
@@ -0,0 +1,22 @@
+#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
+
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
+WORKDIR /app
+EXPOSE 80
+EXPOSE 443
+
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
+WORKDIR /src
+COPY ["TodoApp.Api/TodoApp.Api.csproj", "TodoApp.Api/"]
+RUN dotnet restore "TodoApp.Api/TodoApp.Api.csproj"
+COPY . .
+WORKDIR "/src/TodoApp.Api"
+RUN dotnet build "TodoApp.Api.csproj" -c Release -o /app/build
+
+FROM build AS publish
+RUN dotnet publish "TodoApp.Api.csproj" -c Release -o /app/publish
+
+FROM base AS final
+WORKDIR /app
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "TodoApp.Api.dll"]
\ No newline at end of file
diff --git a/TodoApp.Api/Migrations/20210728100004_InitialCreate.Designer.cs b/TodoApp.Api/Migrations/20210728100004_InitialCreate.Designer.cs
new file mode 100644
index 0000000..0af736d
--- /dev/null
+++ b/TodoApp.Api/Migrations/20210728100004_InitialCreate.Designer.cs
@@ -0,0 +1,42 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+namespace TodoApp.Api.Migrations
+{
+ [DbContext(typeof(TodoContext))]
+ [Migration("20210728100004_InitialCreate")]
+ partial class InitialCreate
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("ProductVersion", "6.0.0-preview.6.21352.1")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("TodoItem", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("bigint")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("IsComplete")
+ .HasColumnType("bit");
+
+ b.Property("Name")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("TodoItems");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/TodoApp.Api/Migrations/20210728100004_InitialCreate.cs b/TodoApp.Api/Migrations/20210728100004_InitialCreate.cs
new file mode 100644
index 0000000..0a9af0f
--- /dev/null
+++ b/TodoApp.Api/Migrations/20210728100004_InitialCreate.cs
@@ -0,0 +1,30 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace TodoApp.Api.Migrations
+{
+ public partial class InitialCreate : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "TodoItems",
+ columns: table => new
+ {
+ Id = table.Column(type: "bigint", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Name = table.Column(type: "nvarchar(max)", nullable: true),
+ IsComplete = table.Column(type: "bit", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_TodoItems", x => x.Id);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "TodoItems");
+ }
+ }
+}
diff --git a/TodoApp.Api/Migrations/TodoContextModelSnapshot.cs b/TodoApp.Api/Migrations/TodoContextModelSnapshot.cs
new file mode 100644
index 0000000..daf596b
--- /dev/null
+++ b/TodoApp.Api/Migrations/TodoContextModelSnapshot.cs
@@ -0,0 +1,40 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+namespace TodoApp.Api.Migrations
+{
+ [DbContext(typeof(TodoContext))]
+ partial class TodoContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("ProductVersion", "6.0.0-preview.6.21352.1")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("TodoItem", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("bigint")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("IsComplete")
+ .HasColumnType("bit");
+
+ b.Property("Name")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("TodoItems");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/TodoApp.Api/Program.cs b/TodoApp.Api/Program.cs
new file mode 100644
index 0000000..62dda5d
--- /dev/null
+++ b/TodoApp.Api/Program.cs
@@ -0,0 +1,82 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using System.ComponentModel.DataAnnotations;
+using static ResultMapper;
+
+var builder = WebApplication.CreateBuilder(args);
+var sqlConnection = builder.Configuration.GetSection("ConnectionStrings")["SqlServer"];
+
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddDbContext(opts => {
+ if (builder.Environment.IsDevelopment() && string.IsNullOrEmpty(sqlConnection))
+ opts.UseInMemoryDatabase("TodoList");
+ else
+ opts.UseSqlServer(sqlConnection);
+});
+
+builder.Services.AddSwaggerGen(opts =>
+ opts.SwaggerDoc("v1", new() { Title = builder.Environment.ApplicationName, Version = "v1" }));
+
+await using WebApplication app = builder.Build();
+
+if (app.Environment.IsDevelopment()) {
+ app.UseDeveloperExceptionPage()
+ .UseSwagger()
+ .UseSwaggerUI();
+}
+
+var basePath = "/api/TodoItems";
+
+// Get All Todos
+app.MapGet(basePath, async ([FromServices] TodoContext _context) => await _context.TodoItems.ToListAsync());
+
+// Get single Todo
+app.MapGet($"{basePath}/{{id}}", async ([FromServices] TodoContext _context, long id) =>
+ await _context.TodoItems.FindAsync(id) is TodoItem todoItem ? Ok(todoItem) : NotFound());
+
+// Update Todo
+app.MapPut($"{basePath}/{{id}}", async ([FromServices] TodoContext _context, long id, TodoItem todoItem) => {
+ if (id != todoItem.Id)
+ return BadRequest();
+
+ _context.Entry(todoItem).State = EntityState.Modified;
+ await _context.SaveChangesAsync();
+
+ return NoContent();
+});
+
+// Create Todo
+app.MapPost(basePath, async ([FromServices] TodoContext _context, TodoItem todoItem) => {
+ await _context.TodoItems.AddAsync(todoItem);
+ await _context.SaveChangesAsync();
+
+ return Created();
+});
+
+// Delete Todo
+app.MapDelete($"{basePath}/{{id}}", async ([FromServices] TodoContext _context, long id) => {
+ if (await _context.TodoItems.FindAsync(id) is TodoItem todoItem) {
+ _context.TodoItems.Remove(todoItem);
+ await _context.SaveChangesAsync();
+ return NoContent();
+ }
+
+ return NotFound();
+});
+
+await app.RunAsync();
+
+public record TodoItem(long Id, [Required] string Name, bool IsComplete);
+
+public class TodoContext : DbContext
+{
+ public TodoContext(DbContextOptions options)
+ : base(options) { }
+
+ public DbSet TodoItems => Set();
+}
+
diff --git a/TodoApp.Api/Properties/launchSettings.json b/TodoApp.Api/Properties/launchSettings.json
new file mode 100644
index 0000000..f3bb1c8
--- /dev/null
+++ b/TodoApp.Api/Properties/launchSettings.json
@@ -0,0 +1,38 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:16255",
+ "sslPort": 44323
+ }
+ },
+ "profiles": {
+ "TodoApp.Api": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:5001;http://localhost:5000",
+ "dotnetRunMessages": true
+ },
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "Docker": {
+ "commandName": "Docker",
+ "launchBrowser": true,
+ "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
+ "publishAllPorts": true,
+ "useSSL": true
+ }
+ }
+}
\ No newline at end of file
diff --git a/TodoApp.Api/ResultMapper.cs b/TodoApp.Api/ResultMapper.cs
new file mode 100644
index 0000000..b47976b
--- /dev/null
+++ b/TodoApp.Api/ResultMapper.cs
@@ -0,0 +1,31 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System.Threading.Tasks;
+
+public static class ResultMapper
+{
+ public static IResult BadRequest() => new StatusCodeResult(StatusCodes.Status400BadRequest);
+
+ public static IResult NotFound() => new StatusCodeResult(StatusCodes.Status404NotFound);
+
+ public static IResult NoContent() => new StatusCodeResult(StatusCodes.Status204NoContent);
+
+ public static IResult Created() => new StatusCodeResult(StatusCodes.Status201Created);
+
+ public static OkResult Ok(T value) => new(value);
+
+ public class OkResult : IResult
+ {
+ private readonly T _value;
+
+ public OkResult(T value)
+ {
+ _value = value;
+ }
+
+ public Task ExecuteAsync(HttpContext httpContext)
+ {
+ return httpContext.Response.WriteAsJsonAsync(_value);
+ }
+ }
+}
\ No newline at end of file
diff --git a/TodoApp.Api/TodoApp.Api.csproj b/TodoApp.Api/TodoApp.Api.csproj
new file mode 100644
index 0000000..f9d1d0a
--- /dev/null
+++ b/TodoApp.Api/TodoApp.Api.csproj
@@ -0,0 +1,20 @@
+
+
+
+ net6.0
+ fea108a6-30be-4cb3-bf03-075ddd3ad926
+ Linux
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TodoApp.Api/appsettings.Development.json b/TodoApp.Api/appsettings.Development.json
new file mode 100644
index 0000000..8983e0f
--- /dev/null
+++ b/TodoApp.Api/appsettings.Development.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ }
+}
diff --git a/TodoApp.Api/appsettings.json b/TodoApp.Api/appsettings.json
new file mode 100644
index 0000000..0399f08
--- /dev/null
+++ b/TodoApp.Api/appsettings.json
@@ -0,0 +1,13 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "AllowedHosts": "*",
+ "ConnectionStrings": {
+ "SqlServer": ""
+ }
+}
diff --git a/TodoApp.sln b/TodoApp.sln
new file mode 100644
index 0000000..e821c33
--- /dev/null
+++ b/TodoApp.sln
@@ -0,0 +1,33 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.31521.260
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoApp.Api", "TodoApp.Api\TodoApp.Api.csproj", "{903CC1CC-25A7-490C-AA47-3DBC6E06B425}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AA459A6F-4273-467B-8BA1-6230BA015A0A}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ Directory.Build.props = Directory.Build.props
+ global.json = global.json
+ version.json = version.json
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {903CC1CC-25A7-490C-AA47-3DBC6E06B425}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {903CC1CC-25A7-490C-AA47-3DBC6E06B425}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {903CC1CC-25A7-490C-AA47-3DBC6E06B425}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {903CC1CC-25A7-490C-AA47-3DBC6E06B425}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {DDD913FD-581C-461C-8E03-6B7D5CC56704}
+ EndGlobalSection
+EndGlobal
diff --git a/global.json b/global.json
new file mode 100644
index 0000000..73b2d3a
--- /dev/null
+++ b/global.json
@@ -0,0 +1,6 @@
+{
+ "sdk": {
+ "version": "6.0",
+ "rollForward": "latestFeature"
+ }
+}
\ No newline at end of file
diff --git a/version.json b/version.json
new file mode 100644
index 0000000..f11fbe5
--- /dev/null
+++ b/version.json
@@ -0,0 +1,10 @@
+{
+ "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
+ "version": "0.1",
+ "publicReleaseRefSpec": [
+ "^refs/heads/main$"
+ ],
+ "cloudBuild": {
+ "setVersionVariables": true
+ }
+}
\ No newline at end of file