BNU: BSc in Computing

CO550: Web Applications

The Design and Development of ASP.NET Web Applications

Week 3 Activities - Razor Pages Database Modelling

Task Lesson Activity Learning Assessment Skill Developed
3.1
  • Software Development Principles
    1. Do Not Repeat Yourself
    2. Keep it simple and easy to understand
    3. Layout and Organise parts logically
    4. Add comments and documentation to explain details
    5. Use a consistent naming convention (Microsoft)
  • Video 5 min Adding Contributors to your GitHub Project
    Share your GitHub Razor Pages Contoso with me
  • ASP.NET Code in GitHub
Git
3.2
  • 60 min Database Modelling
  • 10 min Add Contoso University Menu Items
  • 10 min Update the Index page for Contoso University
  • 20 min Add a models (Course, Student, Enrollment) to an ASP.NET Core Razor Pages Project. MAKE SURE ALL NAVIGATION PROPERTIES ARE VIRTUAL!
  • 5 min Add data annotations to provide data validation
  • 5 min Add a Students folder and then Scaffold the Student model creating CRUD Razor Pages and a database context class

  • NOTE: THE SINGULAR NAMING CONVENTION WHICH CANNOT BE EASILY CHANGED

  • You can rename the database name in the connection string, but it must be unique
  • Examine the Startup.cs class where the database context is added to the startup configurations using Dependancy Injection
  • 5 min Update Program.cs to ensure that the Database is created. This allows for updating the database by deleting the old and creating a new.
  • Run the app and select the Students menu entry. You should be able to add a new student to the database. Check the database in the object explorer.
  • Add a DbSet for Courses and Enrollments. Add a data initialiser (or seed method) with some dample data. Drop the database and re-run the programme
  • 40 min DP Video of Core Razor Pages
    Shows creating the data model classes, adding scaffolded CRUD Pages for Students, and creating and seeding the local SQL Server Database
  • 5 min Download Logbook 2 - Scaffolding
    • Student CRUD Views, Sample data
    Razor Pages, Scaffolding

    Useful Resources

    Week Index