Posted on Leave a comment

List of programming steps to take when building .Net MVC application functionality

Here are the steps to take when adding or building .Net MVC functionality.  Your mileage may vary of course.

  1. Create the domain model.  This is the domain object, not the view model that is passed between the controller and the view.  Typically includes embedded business logic code plus mapping to the database or database calls interfaced as services.
  2. Add the controller.  Make sure the controller name ends with “Controller”.
  3. Create the action-method stub.  We’re only stubbing it out so we can be good little programming robots and write the unit tests first.
  4. If you want to be a dweeb, add unit tests for the action method.  It’ll look something like this:[pastacode lang=”c” manual=”%5BTestMethod%5D%0A%20%20%20%20%20%20%20%20public%20void%20ViewMaps()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Arrange%0A%20%20%20%20%20%20%20%20%20%20%20%20MapsController%20controller%20%3D%20new%20MapsController()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Act%0A%20%20%20%20%20%20%20%20%20%20%20%20ViewResult%20result%20%3D%20controller.ViewMaps()%20as%20ViewResult%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Assert%0A%20%20%20%20%20%20%20%20%20%20%20%20Assert.IsNotNull(result)%3B%0A%20%20%20%20%20%20%20%20%7D” message=”” highlight=”” provider=”manual”/]
  5. Add code to the action method (e.g. return view)[pastacode lang=”c” manual=”public%20ActionResult%20ViewMaps()%0A%7B%0A%20%20%20%20%20return%20View()%3B%0A%7D” message=”” highlight=”” provider=”manual”/]
  6. Add a view.  Right-click in the action method and choose Add View.
  7. Add a view model too.  We could just use ViewBag but a view model gives us all the advantages of a strongly typed view.  It’ll look like this.
    [pastacode lang=”cpp” manual=”namespace%20Testing.Models%0A%7B%0Apublic%20class%20LoginViewModel%20%7B%0A%5BRequired%5D%0Apublic%20string%20UserName%20%7B%20get%3B%20set%3B%20%7D%20%5BRequired%5D%0Apublic%20string%20Password%20%7B%20get%3B%20set%3B%20%7D%0A%7D%0A%7D” message=”” highlight=”” provider=”manual”/]
  8. Add content to the view (hook to the view model)[pastacode lang=”markup” manual=”%3Ch2%3EMy%20City%20Maps%3C%2Fh2%3E%0ASelect%20map%3A%20%0A%3Cselect%20onclick%3D%22GetMap(value)%3B%22%3E%0A%20%20%20%20%3Coption%20value%3D%22Seattle%22%3ESeattle%2C%20WA%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22LasVegas%22%3ELas%20Vegas%2C%20NV%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22SaltLake%22%3ESalt%20Lake%20City%2C%20UT%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Dallas%22%3EDallas%2C%20TX%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Chicago%22%3EChicago%2C%20IL%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22NewYork%22%3ENew%20York%2C%20NY%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Rio%22%3ERio%20de%20Janeiro%2C%20Brazil%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Paris%22%3EParis%2C%20France%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Naples%22%3ENaples%2C%20Italy%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Keta%22%3EKeta%2C%20Ghana%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Beijing%22%3EBeijing%2C%20China%3C%2Foption%3E%0A%20%20%20%20%3Coption%20value%3D%22Sydney%22%3ESydney%2C%20Australia%3C%2Foption%3E%0A%3C%2Fselect%3E%0A%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cdiv%20id%3D’earthMap’%20style%3D%22position%3Arelative%3B%20width%3A400px%3B%20height%3A400px%3B%22%3E%0A%3C%2Fdiv%3E%0A%3Cscript%20charset%3D%22UTF-8%22%20type%3D%22text%2Fjavascript%22%20%0A%20%20%20%20src%3D%22http%3A%2F%2Fdev.virtualearth.net%2Fmapcontrol%2Fmapcontrol.ashx%3Fv%3D6.2%26mkt%3Den-us%22%3E%0A%3C%2Fscript%3E%0A%3Cscript%20type%3D%22text%2Fjavascript%22%3E%0A%20%20%20%20var%20map%20%3D%20null%3B%0A%20%20%20%20var%20mapID%20%3D%20”%3B%0A%0A%20%20%20%20function%20GetMap(mapID)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20switch%20(mapID)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20case%20’Seattle’%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map%20%3D%20new%20VEMap(‘earthMap’)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map.LoadMap(new%20VELatLong(47.6%2C%20-122.33)%2C%2010%20%2C’i’%2C%20true)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20case%20’LasVegas’%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map%20%3D%20new%20VEMap(‘earthMap’)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map.LoadMap(new%20VELatLong(36.17%2C%20-115.14)%2C%2010%20%2C’i’%20%2Ctrue)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20case%20’SaltLake’%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map%20%3D%20new%20VEMap(‘earthMap’)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map.LoadMap(new%20VELatLong(40.75%2C%20-111.89)%2C%2010%20%2C’i’%20%2Ctrue)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20case%20’Dallas’%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map%20%3D%20new%20VEMap(‘earthMap’)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20map.LoadMap(new%20VELatLong(32.78%2C%20-96.8)%2C%2010%20%2C’i’%20%2Ctrue)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20%20%20%0A%3C%2Fscript%3E” message=”” highlight=”” provider=”manual”/]
  9. If you’re using the stock template and want to add a new tab for your view, open Site.master and add your new item to the unordered list.[pastacode lang=”markup” manual=”%3Cli%3E%3C%25%3D%20Html.ActionLink(%22My%20City%20Maps%22%2C%20%22ViewMaps%22%2C%20%22Maps%22)%25%3E%3C%2Fli%3E” message=”” highlight=”” provider=”manual”/]
  10. If you want to be a dweeb, test the application.  Otherwise, push it to production.

 

Leave a Reply

Your email address will not be published. Required fields are marked *