Introduction

In the first Blazor project (Countries and Cities) I mentioned that 'real- world' applications tended to need to maintain one-to-many relationships, and gave as an example purchase orders. Each purchase order record needs to have a 'header' that stores information about the order number, date, supplier, etc. and 'details' that stores information about the various order lines, such as product description, unit price, quantity, etc.
In this project, I am going to use the techniques demonstrated in 'Countries and Cities' to create a basic purchase order system.
However, I intend to throw a few obstacles in my path to make it more of a challenge; I hope to be able to email a pdf of each order to the supplier. I also intend to implement basic authentication, in the first place to record who has requested the purchase order (and to be able to email them confirmation that the order has been placed), but possibly also to implement role-based security around access to parts of the system. One other complication I might tackle is to post the whole order, header and multiple order lines, as a single transaction to the SQL database. No doubt other problems will present themselves as I progress...
Sample Purchase Order
I have used Excel to sketch out a rough idea of how I expect the purchase order to look, as shown below.

The actual input form will undoubtedly look very different, but the colour coding is how I intend data to be entered. Items in yellow will be selected from drop-down lists, i.e. 'Supplier', 'Requested by', 'Product' and 'Tax Rate'. Blue items will be derived from the items selected from drop-down lists, but will be able to be over-written, other than the 'Order Date' which will default to the current date. Derived items include the supplier's address and email address, product description and unit price. Items in green, i.e. 'Quantity' will be entered directly by the user. Items in orange will be calculated, or in the case of 'Order No' be assigned by the system. Orange items will not be able to be changed by the user.
I live in the UK and we have a sales tax called VAT (Value Added Tax), and the application will be modelled on VAT, however, to make the forms and data slightly more generic I am going to replace 'VAT' with 'Tax'.
Approach
This project is going to differ in one significant aspect from the previous 'Countries & Cities' project. In that first project I did not start documenting, and recording YouTube videos, before I had pretty much finished the project and knew what I was doing (at least as far as the project was concerned). This time I'm going to start documenting what I am doing as I do it. I therefore fully anticipate that things will go wrong, either disastrously and I will have to abandon the project or some part of it, or less disastrously but which could mean I will have to back-track and correct a previous error or go down a different route.
Rather than be constantly referring back to the documentation in 'Countries & Cities' I plan to make the documentation of this project completely self-contained. This, of course, means that if you have read the documentation for 'Countries & Cities', or watched the videos, there will be duplication of steps already taken, but I am told repetition is a good way to learn! (I also hope that I might improve techniques and patterns already discovered.)
This project will also implement the built-in authentication that Blazor projects can use. My initial purpose in this is to provide verified data for the 'Requested by' field, but I also plan to restrict access to some parts of the system using roles later in the project.
I will start with the database and then move onto the C# code.
Prerequisites
Install the following:
- Visual Studio community 2019 (link here) I'm using version 16.8.3 (This version allows the use of .Net 5.0, amongst other features.)
- Microsoft SQL Server 2019 Express (link here - make sure you download the free Express version.)
- Microsoft SQL Server Management Studio (link here) I'm using version 18.8
lan Simpson has produced a series of 16 short YouTube videos on "Blazor + Dapper CRUD". Rather than reproduce those videos I recommend watching all 16 (link here). For the uninitiated CRUD is short for Create, Read, Update, Delete - the basic interactions between the user and a database.
Even better, Alan has created an amazing little program in C# to do most of the code generation for these basic CRUD operations. We will be using his program, so I would advise watching his 3 videos on that subject (link here).