Join Jess Chadwick for an in-depth discussion in this video Exploring the sample application, part of ASP.NET Core: Razor Pages.
- [Narrator] Throughout this course, I'll be using the various features that Razor Pages offers to build a sample application called Topsy Turvy Cake Design, an online recipe catalog for the fictitious brand to share and manage their favorite recipes with their loyal customers. Here's what the site will look like when it's finished. The homepage of this site will have a dynamically generated list of recipes and each one of these will contain a link which will bring you to the details page for that recipe.
What's more, you can even add recipes to this site using this "add recipe" button. However, adding or editing of recipes is only allowed by authenticated users, so when I log in, I can fill out the html form and add a new recipe to the site. Now the ability to add and edit recipes is great, but at this point, the most important aspect of this demo site is how it's data access works.
Because database access is well outside of the scope of this course, I will not be going into detail about how it's implemented. For that, I encourage you to watch our other great courses on Entity Framework Core. Instead, I'll walk you through the classes very quickly and give you a high-level overview now so that you're not caught by surprise when I copy and paste these classes in later. The first is iRecipe Service, a simple interface for managing recipe data.
The second, is the recipe model itself. Note the neat little trick that I have here where the get inline image source method formats the bytes of the recipe image property into a base 64 encoded string to be rendered directly to the page in an image tag. This allows me to include the image in the page without an additional web request to load that image. Then there's the recipes DB context, the Entity Framework Core database context that allows me to interact with the database in an object-oriented manner.
Then there's the implementation of that iRecipe Service interface that wraps the interface DB context to add some logic around simple database operations. And then finally, a class that generates the recipe test data so my site isn't empty every time I rebuild it. Note that since this file has inline image data, it's pretty big and it might actually crash some editors if you load it. And that's it, a somewhat simple, but effective data management layer.
These are the classes that I've created prior to the course and that I'll be consuming throughout the course to manage recipe data. When the time comes to use them, these classes will be waiting for you in the artifacts folder of your exercise files
- Creating a new application
- Setting up pages
- Rendering dynamic content
- Reusing markup with layouts
- Increasing the maintainability of pages
- Processing data
- Validating input
- Securing an application