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

// May 11th, 2017 // Computers & Programming

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:
    [TestMethod]
            public void ViewMaps()
            {
                // Arrange
                MapsController controller = new MapsController();
    
                // Act
                ViewResult result = controller.ViewMaps() as ViewResult;
    
                // Assert
                Assert.IsNotNull(result);
            }
  5. Add code to the action method (e.g. return view)
    public ActionResult ViewMaps()
    {
         return View();
    }
  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.
    namespace Testing.Models
    {
    public class LoginViewModel {
    [Required]
    public string UserName { get; set; } [Required]
    public string Password { get; set; }
    }
    }
  8. Add content to the view (hook to the view model)
    <h2>My City Maps</h2>
    Select map: 
    <select onclick="GetMap(value);">
        <option value="Seattle">Seattle, WA</option>
        <option value="LasVegas">Las Vegas, NV</option>
        <option value="SaltLake">Salt Lake City, UT</option>
        <option value="Dallas">Dallas, TX</option>
        <option value="Chicago">Chicago, IL</option>
        <option value="NewYork">New York, NY</option>
        <option value="Rio">Rio de Janeiro, Brazil</option>
        <option value="Paris">Paris, France</option>
        <option value="Naples">Naples, Italy</option>
        <option value="Keta">Keta, Ghana</option>
        <option value="Beijing">Beijing, China</option>
        <option value="Sydney">Sydney, Australia</option>
    </select>
    <br />
    <br />
    <div id='earthMap' style="position:relative; width:400px; height:400px;">
    </div>
    <script charset="UTF-8" type="text/javascript" 
        src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-us">
    </script>
    <script type="text/javascript">
        var map = null;
        var mapID = '';
    
        function GetMap(mapID)
        {
            switch (mapID)
            {
                case 'Seattle':
                    map = new VEMap('earthMap');
                    map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'i', true);
                    break;
                case 'LasVegas':
                    map = new VEMap('earthMap');
                    map.LoadMap(new VELatLong(36.17, -115.14), 10 ,'i' ,true);
                    break;
                case 'SaltLake':
                    map = new VEMap('earthMap');
                    map.LoadMap(new VELatLong(40.75, -111.89), 10 ,'i' ,true);
                    break;
                case 'Dallas':
                    map = new VEMap('earthMap');
                    map.LoadMap(new VELatLong(32.78, -96.8), 10 ,'i' ,true);
                    break;
             }
        }   
    </script>
  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.
    <li><%= Html.ActionLink("My City Maps", "ViewMaps", "Maps")%></li>
  10. If you want to be a dweeb, test the application.  Otherwise, push it to production.

 

No related articles or news found.





« « Previous Article: Cell phone jammer circuit (GSM1900 network)     » » Next Article: Check out the WannaCry/WannaCryptor/WanaDecryptor (WCry 2.0) ransomware indicators


Leave a Reply

You must be logged in to post a comment.

%d bloggers like this: