diff --git a/.gitignore b/.gitignore
index 9491a2f..a62e968 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
## 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
+## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
@@ -29,7 +29,6 @@ x86/
bld/
[Bb]in/
[Oo]bj/
-[Oo]ut/
[Ll]og/
[Ll]ogs/
@@ -58,11 +57,14 @@ dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
-# .NET Core
+# .NET
project.lock.json
project.fragment.lock.json
artifacts/
+# Tye
+.tye/
+
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
@@ -91,6 +93,7 @@ StyleCopReport.xml
*.tmp_proj
*_wpftmp.csproj
*.log
+*.tlog
*.vspscc
*.vssscc
.builds
@@ -294,6 +297,17 @@ node_modules/
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
+# Visual Studio 6 auto-generated project file (contains which files were open etc.)
+*.vbp
+
+# Visual Studio 6 workspace and project file (working project files containing files to include in project)
+*.dsw
+*.dsp
+
+# Visual Studio 6 technical files
+*.ncb
+*.aps
+
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
@@ -350,6 +364,9 @@ ASALocalRun/
# Local History for Visual Studio
.localhistory/
+# Visual Studio History (VSHistory) files
+.vshistory/
+
# BeatPulse healthcheck temp database
healthchecksdb
@@ -360,4 +377,108 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
-FodyWeavers.xsd
\ No newline at end of file
+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
+*.sln.iml
+
+##
+## Visual studio for Mac
+##
+
+
+# globs
+Makefile.in
+*.userprefs
+*.usertasks
+config.make
+config.status
+aclocal.m4
+install-sh
+autom4te.cache/
+*.tar.gz
+tarballs/
+test-results/
+
+# Mac bundle stuff
+*.dmg
+*.app
+
+# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
+# Windows thumbnail cache files
+Thumbs.db
+ehthumbs.db
+ehthumbs_vista.db
+
+# Dump file
+*.stackdump
+
+# Folder config file
+[Dd]esktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
+
+*/**/bin/Debug
+*/**/bin/Release
+*/**/obj/Debug
+*/**/obj/Release
+/exercise.pizzashopapi/appsettings.json
+/exercise.pizzashopapi/appsettings.Development.json
diff --git a/README.md b/README.md
index 4b93bbd..336878e 100644
--- a/README.md
+++ b/README.md
@@ -1,45 +1,21 @@
-# Database Migrations Exercise
+# C# Migrations Exercise
-## Learning Objectives
-- Use Entity Framework migrations to manage changes to table structures
+## Pizza Shop Api
+Pizza Shop needs a very simple ordering system with just just 3 tables:
-## Instructions
+-Customer
+-Pizza
+-Order
-1. Fork this repository
-2. Clone your fork to your machine
-3. Open the project in Visual Studio
-4. I have restricted config from being uploaded to github (see the end of .gitignore)
- What you need to do now is change the PizzaContext.cs file to use your ElephantSql instance.
- If you Ctrl+c then Ctrol+v on the App.config.fake file to create a duplicate of this. Remove the extension
- .fake so the file name is App.config Now you can look at the connection string and replace each item with your own Elephant credentials.
+```
+-Add an appsettings.json file and connect to your database.
+-Run a migration to create the Customer / Pizza tables
+-Add an address to the Customer object then run another migration
+-Complete the Order model with an Id, OrderDate and a foreign key to the Customer and Pizza (and include a Pizza/Customer property). A single order only has 1 customer ordering 1 pizza.
+-Run another migration to add the latest updates to the database
+-Seed some data for the orders... Dave likes a Cheese & Pineapple pizza and Nigel likes Vegan ones.
+-Complete the only method in the Repository to GetOrders() being sure to include the customer and pizza in the results.
+```
-5. In the Package Manager Console initiate the migraion: PM> Add-Migration InitialCreate
-
-Build started...
-Build succeeded.
-To undo this action, use Remove-Migration.
-
-This should generate a Migrations folder with some c# to create the database.
-
-
-6. In the Package Manager Console update the database : PM> Update-Database
-
-Build started...
-Build succeeded.
-Applying migration '20230424151917_InitialCreate'.
- something like this should appear!
-
-
-7. Now make a change.
-
-
-
-## FYI
-
-If you are using VSCode you can install EF using: $ dotnet tool install -g dotnet-ef
-
-and run commands like this: $ dotnet ef migrations add InitialCreate
- $ dotnet ef database update
-
-from your console.
\ No newline at end of file
+Try and complete this exercise with at least 3 migrations
diff --git a/csharp-api-migrations.Main/.gitignore b/csharp-api-migrations.Main/.gitignore
deleted file mode 100644
index 4223bbd..0000000
--- a/csharp-api-migrations.Main/.gitignore
+++ /dev/null
@@ -1,482 +0,0 @@
-## 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/main/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
-project.lock.json
-project.fragment.lock.json
-artifacts/
-
-# Tye
-.tye/
-
-# 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
-
-# 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 6 auto-generated project file (contains which files were open etc.)
-*.vbp
-
-# Visual Studio 6 workspace and project file (working project files containing files to include in project)
-*.dsw
-*.dsp
-
-# Visual Studio 6 technical files
-*.ncb
-*.aps
-
-# 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/
-
-# Visual Studio History (VSHistory) files
-.vshistory/
-
-# 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
-*.sln.iml
-
-##
-## Visual studio for Mac
-##
-
-
-# globs
-Makefile.in
-*.userprefs
-*.usertasks
-config.make
-config.status
-aclocal.m4
-install-sh
-autom4te.cache/
-*.tar.gz
-tarballs/
-test-results/
-
-# Mac bundle stuff
-*.dmg
-*.app
-
-# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
-# General
-.DS_Store
-.AppleDouble
-.LSOverride
-
-# Icon must end with two \r
-Icon
-
-
-# Thumbnails
-._*
-
-# Files that might appear in the root of a volume
-.DocumentRevisions-V100
-.fseventsd
-.Spotlight-V100
-.TemporaryItems
-.Trashes
-.VolumeIcon.icns
-.com.apple.timemachine.donotpresent
-
-# Directories potentially created on remote AFP share
-.AppleDB
-.AppleDesktop
-Network Trash Folder
-Temporary Items
-.apdisk
-
-# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
-# Windows thumbnail cache files
-Thumbs.db
-ehthumbs.db
-ehthumbs_vista.db
-
-# Dump file
-*.stackdump
-
-# Folder config file
-[Dd]esktop.ini
-
-# Recycle Bin used on file shares
-$RECYCLE.BIN/
-
-# Windows Installer files
-*.cab
-*.msi
-*.msix
-*.msm
-*.msp
-
-# Windows shortcuts
-*.lnk
-
-*.csv
-DataStudents/*.csv
-App.config
-!DataImport/files/*.csv
\ No newline at end of file
diff --git a/csharp-api-migrations.Main/App.config.fake b/csharp-api-migrations.Main/App.config.fake
deleted file mode 100644
index 2f61190..0000000
--- a/csharp-api-migrations.Main/App.config.fake
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
diff --git a/csharp-api-migrations.Main/Data/PizzaContext.cs b/csharp-api-migrations.Main/Data/PizzaContext.cs
deleted file mode 100644
index 6b12222..0000000
--- a/csharp-api-migrations.Main/Data/PizzaContext.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using csharp_api_migrations.Main.Models;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.Configuration;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Xml.Linq;
-
-namespace csharp_api_migrations.Main.Data
-{
- public class PizzaContext : DbContext
- {
-
- public DbSet Products { get; set; }
- public DbSet Orders { get; set; }
- public DbSet Customers { get; set; }
- public DbSet OrderDetails { get; set; }
-
-
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- optionsBuilder.UseNpgsql(ConfigurationManager.ConnectionStrings["PostgreSQL"].ConnectionString);
- }
-
- }
-}
diff --git a/csharp-api-migrations.Main/DataImport/Interface/IFileImporter.cs b/csharp-api-migrations.Main/DataImport/Interface/IFileImporter.cs
deleted file mode 100644
index 02ee955..0000000
--- a/csharp-api-migrations.Main/DataImport/Interface/IFileImporter.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using csharp_api_migrations.Main.Models;
-using Microsoft.EntityFrameworkCore;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace csharp_api_migrations.Main.DataImport.Interface
-{
- public interface IFileImporter
- {
- List ProcessCustomersCsvFile(string path);
- List ProcessProductsCsvFile(string path);
-
-
- }
-}
diff --git a/csharp-api-migrations.Main/DataImport/files/Customers.csv b/csharp-api-migrations.Main/DataImport/files/Customers.csv
deleted file mode 100644
index 5f28270..0000000
--- a/csharp-api-migrations.Main/DataImport/files/Customers.csv
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/csharp-api-migrations.Main/DataImport/files/Orders.json b/csharp-api-migrations.Main/DataImport/files/Orders.json
deleted file mode 100644
index 5f28270..0000000
--- a/csharp-api-migrations.Main/DataImport/files/Orders.json
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/csharp-api-migrations.Main/DataImport/files/Products.csv b/csharp-api-migrations.Main/DataImport/files/Products.csv
deleted file mode 100644
index 5f28270..0000000
--- a/csharp-api-migrations.Main/DataImport/files/Products.csv
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/csharp-api-migrations.Main/Enums.cs b/csharp-api-migrations.Main/Enums.cs
deleted file mode 100644
index fd219b0..0000000
--- a/csharp-api-migrations.Main/Enums.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace csharp_api_migrations.Main
-{
- public class Enums
- {
- public enum PersonRole
- {
- Teacher,
- Student
- }
- }
-}
diff --git a/csharp-api-migrations.Main/Models/Customer.cs b/csharp-api-migrations.Main/Models/Customer.cs
deleted file mode 100644
index 521cc18..0000000
--- a/csharp-api-migrations.Main/Models/Customer.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using static csharp_api_migrations.Main.Enums;
-
-namespace csharp_api_migrations.Main.Models
-{
- public class Customer
- {
- [Key]
- public int Id { get; set; }
- [Required]
- public string Firstname { get; set; }
- [Required]
- public string Lastname { get; set; }
- public string? Address { get; set; }
- public string? Phone { get; set; }
- public ICollection Orders { get; set; } = null;
- }
-}
diff --git a/csharp-api-migrations.Main/Models/Order.cs b/csharp-api-migrations.Main/Models/Order.cs
deleted file mode 100644
index 4e12548..0000000
--- a/csharp-api-migrations.Main/Models/Order.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System.ComponentModel.DataAnnotations;
-
-namespace csharp_api_migrations.Main.Models
-{
- public class Order
- {
- [Key]
- public int Id { get; set; }
- public DateTime OrderPlaced { get; set; }
- public DateTime? OrderProcessed { get; set; }
- public int CustomerId { get; set; }
- public Customer Customer { get; set; }
- public ICollection OrderDetails { get; set; } = null;
-
- }
-}
\ No newline at end of file
diff --git a/csharp-api-migrations.Main/Models/OrderDetail.cs b/csharp-api-migrations.Main/Models/OrderDetail.cs
deleted file mode 100644
index 582dda2..0000000
--- a/csharp-api-migrations.Main/Models/OrderDetail.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace csharp_api_migrations.Main.Models
-{
- public class OrderDetail
- {
- public int Id { get; set; }
- public int Quantity { get; set; }
- public int ProductId { get; set; }
- public int OrderId { get; set; }
- public Order Order { get; set; }
- public Product Product { get; set; }
-
- }
-}
diff --git a/csharp-api-migrations.Main/Models/Product.cs b/csharp-api-migrations.Main/Models/Product.cs
deleted file mode 100644
index 87fcf94..0000000
--- a/csharp-api-migrations.Main/Models/Product.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.ComponentModel.DataAnnotations.Schema;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace csharp_api_migrations.Main.Models
-{
- public class Product
- {
- [Key]
- public int Id { get; set; }
-
- [Required]
- public string Name { get; set; }
-
- [Column(TypeName ="decimal(6,2)")]
- public decimal Cost { get; set; }
-
- public Image
-
- }
-}
diff --git a/csharp-api-migrations.Main/Program.cs b/csharp-api-migrations.Main/Program.cs
deleted file mode 100644
index 881e29a..0000000
--- a/csharp-api-migrations.Main/Program.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-Console.WriteLine("Entity Framework");
\ No newline at end of file
diff --git a/exercise.pizzashopapi/Controllers/WeatherForecastController.cs b/exercise.pizzashopapi/Controllers/WeatherForecastController.cs
new file mode 100644
index 0000000..a4905c4
--- /dev/null
+++ b/exercise.pizzashopapi/Controllers/WeatherForecastController.cs
@@ -0,0 +1,32 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace exercise.pizzashopapi.Controllers;
+
+[ApiController]
+[Route("[controller]")]
+public class WeatherForecastController : ControllerBase
+{
+ private static readonly string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ private readonly ILogger _logger;
+
+ public WeatherForecastController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet(Name = "GetWeatherForecast")]
+ public IEnumerable Get()
+ {
+ return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+ {
+ Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
+ TemperatureC = Random.Shared.Next(-20, 55),
+ Summary = Summaries[Random.Shared.Next(Summaries.Length)]
+ })
+ .ToArray();
+ }
+}
diff --git a/exercise.pizzashopapi/Data/DataContext.cs b/exercise.pizzashopapi/Data/DataContext.cs
new file mode 100644
index 0000000..5bfdd71
--- /dev/null
+++ b/exercise.pizzashopapi/Data/DataContext.cs
@@ -0,0 +1,23 @@
+using exercise.pizzashopapi.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace exercise.pizzashopapi.Data
+{
+ public class DataContext : DbContext
+ {
+ private string connectionString;
+ public DataContext()
+ {
+ var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
+ connectionString = configuration.GetValue("ConnectionStrings:DefaultConnectionString");
+
+ }
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ optionsBuilder.UseNpgsql(connectionString);
+
+ }
+ public DbSet Pizzas { get; set; }
+ public DbSet Customers { get; set; }
+ }
+}
diff --git a/exercise.pizzashopapi/Data/Seeder.cs b/exercise.pizzashopapi/Data/Seeder.cs
new file mode 100644
index 0000000..e144c19
--- /dev/null
+++ b/exercise.pizzashopapi/Data/Seeder.cs
@@ -0,0 +1,34 @@
+using exercise.pizzashopapi.Models;
+
+namespace exercise.pizzashopapi.Data
+{
+ public static class Seeder
+ {
+ public static void SeedPizzaShopApi(this WebApplication app)
+ {
+ using(var db = new DataContext())
+ {
+ if(!db.Customers.Any())
+ {
+ db.Add(new Customer() { Name="Nigel" });
+ db.Add(new Customer() { Name = "Dave" });
+ db.SaveChanges();
+ }
+ if(!db.Pizzas.Any())
+ {
+ db.Add(new Pizza() { Name = "Cheese & Pineapple" });
+ db.Add(new Pizza() { Name = "Vegan Cheese Tastic" });
+ db.SaveChanges();
+
+ }
+
+ //order data
+ if(1==1)
+ {
+
+ db.SaveChanges();
+ }
+ }
+ }
+ }
+}
diff --git a/exercise.pizzashopapi/EndPoints/PizzaShopApi.cs b/exercise.pizzashopapi/EndPoints/PizzaShopApi.cs
new file mode 100644
index 0000000..a4c2c12
--- /dev/null
+++ b/exercise.pizzashopapi/EndPoints/PizzaShopApi.cs
@@ -0,0 +1,20 @@
+using exercise.pizzashopapi.Repository;
+using Microsoft.AspNetCore.Mvc;
+
+namespace exercise.pizzashopapi.EndPoints
+{
+ public static class PizzaShopApi
+ {
+ public static void ConfigurePizzaShopApi(this WebApplication app)
+ {
+ app.MapGet("/pizzas", GetPizzas);
+ }
+
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public static async Task GetPizzas(IRepository repository)
+ {
+ return Results.Ok(repository.GetOrders());
+ }
+ }
+}
diff --git a/exercise.pizzashopapi/Models/Customer.cs b/exercise.pizzashopapi/Models/Customer.cs
new file mode 100644
index 0000000..2ca83bd
--- /dev/null
+++ b/exercise.pizzashopapi/Models/Customer.cs
@@ -0,0 +1,10 @@
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace exercise.pizzashopapi.Models
+{
+ public class Customer
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/exercise.pizzashopapi/Models/Order.cs b/exercise.pizzashopapi/Models/Order.cs
new file mode 100644
index 0000000..fbe6113
--- /dev/null
+++ b/exercise.pizzashopapi/Models/Order.cs
@@ -0,0 +1,10 @@
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace exercise.pizzashopapi.Models
+{
+ public class Order
+ {
+
+
+ }
+}
diff --git a/exercise.pizzashopapi/Models/Pizza.cs b/exercise.pizzashopapi/Models/Pizza.cs
new file mode 100644
index 0000000..5c085ec
--- /dev/null
+++ b/exercise.pizzashopapi/Models/Pizza.cs
@@ -0,0 +1,12 @@
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace exercise.pizzashopapi.Models
+{
+
+ public class Pizza
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public decimal Price { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/exercise.pizzashopapi/Program.cs b/exercise.pizzashopapi/Program.cs
new file mode 100644
index 0000000..6e3a526
--- /dev/null
+++ b/exercise.pizzashopapi/Program.cs
@@ -0,0 +1,34 @@
+using exercise.pizzashopapi.Data;
+using exercise.pizzashopapi.EndPoints;
+using exercise.pizzashopapi.Repository;
+
+var builder = WebApplication.CreateBuilder(args);
+
+// Add services to the container.
+
+builder.Services.AddControllers();
+builder.Services.AddScoped();
+builder.Services.AddDbContext();
+// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddSwaggerGen();
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+if (app.Environment.IsDevelopment())
+{
+ app.UseSwagger();
+ app.UseSwaggerUI();
+}
+
+app.UseHttpsRedirection();
+
+app.UseAuthorization();
+
+app.MapControllers();
+
+app.ConfigurePizzaShopApi();
+
+app.SeedPizzaShopApi();
+app.Run();
diff --git a/exercise.pizzashopapi/Properties/launchSettings.json b/exercise.pizzashopapi/Properties/launchSettings.json
new file mode 100644
index 0000000..1d7269e
--- /dev/null
+++ b/exercise.pizzashopapi/Properties/launchSettings.json
@@ -0,0 +1,41 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:39663",
+ "sslPort": 44368
+ }
+ },
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "http://localhost:5070",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "applicationUrl": "https://localhost:7138;http://localhost:5070",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "swagger",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/exercise.pizzashopapi/Repository/IRepository.cs b/exercise.pizzashopapi/Repository/IRepository.cs
new file mode 100644
index 0000000..9a674a8
--- /dev/null
+++ b/exercise.pizzashopapi/Repository/IRepository.cs
@@ -0,0 +1,9 @@
+using exercise.pizzashopapi.Models;
+
+namespace exercise.pizzashopapi.Repository
+{
+ public interface IRepository
+ {
+ IEnumerable GetOrders();
+ }
+}
diff --git a/exercise.pizzashopapi/Repository/Repository.cs b/exercise.pizzashopapi/Repository/Repository.cs
new file mode 100644
index 0000000..fdcc0da
--- /dev/null
+++ b/exercise.pizzashopapi/Repository/Repository.cs
@@ -0,0 +1,13 @@
+using exercise.pizzashopapi.Data;
+using exercise.pizzashopapi.Models;
+
+namespace exercise.pizzashopapi.Repository
+{
+ public class Repository : IRepository
+ {
+ public IEnumerable GetOrders()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/exercise.pizzashopapi/WeatherForecast.cs b/exercise.pizzashopapi/WeatherForecast.cs
new file mode 100644
index 0000000..864ca65
--- /dev/null
+++ b/exercise.pizzashopapi/WeatherForecast.cs
@@ -0,0 +1,12 @@
+namespace exercise.pizzashopapi;
+
+public class WeatherForecast
+{
+ public DateOnly Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string? Summary { get; set; }
+}
diff --git a/csharp-api-migrations.Main/csharp-api-migrations.Main.csproj b/exercise.pizzashopapi/exercise.pizzashopapi.csproj
similarity index 56%
rename from csharp-api-migrations.Main/csharp-api-migrations.Main.csproj
rename to exercise.pizzashopapi/exercise.pizzashopapi.csproj
index 7f88f60..19534b8 100644
--- a/csharp-api-migrations.Main/csharp-api-migrations.Main.csproj
+++ b/exercise.pizzashopapi/exercise.pizzashopapi.csproj
@@ -1,29 +1,28 @@
-
+
- Exe
net7.0
- csharp_api_migrations.Main
- enable
enable
+ enable
-
-
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
+
-
-
-
-
diff --git a/csharp-api-migrations.sln b/exercise.sln
similarity index 59%
rename from csharp-api-migrations.sln
rename to exercise.sln
index f90f0f3..51e183b 100644
--- a/csharp-api-migrations.sln
+++ b/exercise.sln
@@ -3,10 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-api-migrations.Main", "csharp-api-migrations.Main\csharp-api-migrations.Main.csproj", "{DB013D73-ED7B-456A-94D9-AAE91D04ADA2}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exercise.pizzashopapi", "exercise.pizzashopapi\exercise.pizzashopapi.csproj", "{9ADDE5F2-B3CC-4BD5-98F3-3999C5059890}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4961AF51-E15D-4AD8-9659-9E05A0096ECE}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E3DD87B3-716C-42D7-A894-2DCA702A46B2}"
ProjectSection(SolutionItems) = preProject
+ .gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
@@ -16,10 +17,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {DB013D73-ED7B-456A-94D9-AAE91D04ADA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {DB013D73-ED7B-456A-94D9-AAE91D04ADA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {DB013D73-ED7B-456A-94D9-AAE91D04ADA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {DB013D73-ED7B-456A-94D9-AAE91D04ADA2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9ADDE5F2-B3CC-4BD5-98F3-3999C5059890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9ADDE5F2-B3CC-4BD5-98F3-3999C5059890}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9ADDE5F2-B3CC-4BD5-98F3-3999C5059890}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9ADDE5F2-B3CC-4BD5-98F3-3999C5059890}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE