MVC App 5, Diy Multi-table/relational DB


Main Page

Assignment Description

This assignment was created to test our overall understanding of the previous homeworks and put them all into one challenge. Starting with no database, create two scripts to create the tables and populate them with basic seed data. Then, use code-first style of creating our model to interact with our database. After that, implement the controller and views followed by creating a home controller with AJAX to view each db live, without reloading. I wrote this as close to a guide as possible, to help with the in class final.


First Steps Up.sql and Down.sql

Below I show the completed initDB.sql file as well as the populate.sql file. Each of these is fairly self-explanatory. The main thing is to make sure you understand the table relationships before you go starting it. That way you can set up the proper primary and secondary keys.



Code First Model Creation

Creating the model is easy once you have the database ready. It's as easy as following the dialogue boxes and making sure everything is properly checked off. When completed, a model is ready to use in your controller.


Autogenerate Controllers other than Home with views

This is fairly self explanatory as well. Using this option you can auto generate the desired controller and some basic controller logic for the artist class. Then follow that to create some basic controllers for the other needed tables. These tables will just output what is currently inside the databse. Since it is a small amount of information, no need for pagination at the moment.



Add to shared Layout / Custom Routing in routeconfig

The shared layout must be updated to add the necessary links at the top of the page. As well as the @rendersection code at the bottom of the page.



Create Partial Class

A partial class is necessary when we need to combine potential variables in the database. As shown below we create a new variable "fullname" from adding two strings together. This is useful for when we are testing string length for a requirement of this assignment.


Restrict Name length in Controller, and View.

To restrict the name lenght we add restrictions inside the controller as well as the view.


AJAX


Create HomeController and view.

Create a homeController and index view for our AJAX page. The view should have an area that can be used to output the needed ajax from our genre.js file. At the top of our view, you can see a for each loop that creates the necessary buttons.



Javascript Backend for AJAX

The backend for AJAX is shown below in the genre.js file. It is just two functions created to do the necessary actions on the view. See it in action below!


Conclusion

This homework was essentially to build a simple MVC database web application from scratch. Although challenging, it shows how useful the MVC Asp.net 5 framework can really be. Many projects could be made simpler, or at least easier to get up and running quickly with some background knowledge of how MVC works.



Working Project Screenshots















Link to: Homework Eight

Link to: Repository for hw8






© Sam Wetzel 2017

swetzel13@wou.edu