FatModel Quick Start Guide

Similar documents
FatModel Version 1.1. Best Practices Framework for ASP.Net MVC. By LomaCons

Using Visual Studio 2017

Ten good practices for ASP.NET MVC applications

Course Outline. ASP.NET MVC 5 Development Training Course ASPNETMVC5: 5 days Instructor Led. About this Course

The core of Tapestry's form support is the Form component. The Form component encloses (wraps around) all the other field components such

20486-Developing ASP.NET MVC 4 Web Applications

InstallKey Version 5.7

Developing ASP.NET MVC 5 Web Applications

Making a live edit contact list with Coldbox REST & Vue.js

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

SportsStore: Completing the Cart

20486: Developing ASP.NET MVC 4 Web Applications

Developing ASP.NET MVC 4 Web Applications

Visual Studio Course Developing ASP.NET MVC 5 Web Applications

Bringing Together One ASP.NET

5 Years Integrated M.Sc. (IT) 6th Semester Web Development using ASP.NET MVC Practical List 2016

COURSE 20486B: DEVELOPING ASP.NET MVC 4 WEB APPLICATIONS

20486: Developing ASP.NET MVC 4 Web Applications (5 Days)

Using the PDSA Security System

Developing ASP.NET MVC 4 Web Applications

Index. Bower, 133, 352 bower.json file, 376 Bundling files, 157

How to use PDFlib Products with the.net Framework

Understanding ASP.NET MVC Model Binding

Working Bootstrap Contact form with PHP and AJAX

Developing ASP.NET MVC 5 Web Applications


Course 20486B: Developing ASP.NET MVC 4 Web Applications

Dingle Coderdojo 6. Project Part 2 (of 2) - Movie Poster And Actor! - Lookup. Week 6

EVALUATION COPY. Unauthorized reproduction or distribution is prohibitied ASP.NET MVC USING C#

Workspace Desktop Edition Deployment Guide. Team Communicator Options

Project Part 2 (of 2) - Movie Poster And Actor! - Lookup

20486 Developing ASP.NET MVC 5 Web Applications

SAML v1.1 for.net Developer Guide

HangFire Documentation

This project will use an API from to retrieve a list of movie posters to display on screen.

Description: This feature will enable user to send messages from website to phone number.

The Grumpy Old Programmer s First MV6.NET Core App

User manual Scilab Cloud API

C#.NET Course Content

Developing and deploying MVC4/HTML5 SDK application to IIS DigitalOfficePro Inc.

Paythru Remote Fields

Lampiran. SetoransController

Programming Fundamentals of Web Applications

Overview... 7 Tabs... 8 Selected Tables... 8 Load Tables Button Selected Views... 8 Load Views Button Clear Selection Button...

ClearPath eportal Developer Help

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

Real-Time SignalR. Overview

SportsStore: Administration

Deploying Haystack Applications

20486C: Developing ASP.NET MVC 5 Web Applications

Pro ASP.NET MVC 2 Framework

Microsoft Developing ASP.NET MVC 4 Web Applications

Building Effective ASP.NET MVC 5.x Web Applications using Visual Studio 2013

Developing ASP.NET MVC 4 Web Applications

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

Justin Jones 21 st February 2013 Version 1.1 Setting up an MVC4 Multi-Tenant Site

Assessment Environment - Overview

ASP.NET Web Forms Programming Using Visual Basic.NET

APACHE SLING & FRIENDS TECH MEETUP BERLIN, SEPTEMBER Hypermedia API Tools for Sling (HApi) Andrei Dulvac, Adobe

Integrating Angular with ASP.NET Core RESTful Services. Dan Wahlin

.NET Programming Guide. Server

Module 4 Microsoft Azure Messaging Services

ASP.NET MVC Training

SharpShooter Reports.Web Getting Started (ASP.NET MVC3+Razor)

SECURED PROGRAMMING IN.NET DETAILED TRAINING CONTENT INDUSTRIAL TRAINING PROGRAM ( )

Developing ASP.NET MVC 5 Web Applications. Course Outline

IN ACTION. Jeffrey Palermo Jimmy Bogard Eric Hexter Matthew Hinze Jeremy Skinner. Phil Haack. Third edition of ASP.NET MVC in Action FOREWORD BY

: 20488B: Customized Developing Microsoft SharePoint Server

VuGen.NET Protocol Recording Best Practices and Troubleshooting

Developing ASP.Net MVC 4 Web Application

Using SQL Server in C#

This tutorial is designed for software programmers who would like to learn the basics of ASP.NET Core from scratch.

MVC :: Understanding Models, Views, and Controllers

User manual Scilab Cloud API

RONAN RATTY X BSC (HONS) IN COMPUTING PROJECT: CLEVADEALS FINAL REPORT

Developing Web Applications Using Microsoft Visual Studio 2008 SP1

vfire 9.5 Prerequisites Guide Version 1.1

Haystack Overview. Chapter 1. Table of Contents

Participant Handbook

Developing ASP.NET MVC Web Applications (486)

Introduction to Microsoft.NET Framework Programming using VS 2005 (C#)

Action-packed controllers

DEVELOPING WEB APPLICATIONS WITH MICROSOFT VISUAL STUDIO Course: 10264A; Duration: 5 Days; Instructor-led

MongoDB Web Architecture

20489: Developing Microsoft SharePoint Server 2013 Advanced Solutions

Front End Programming

Documentation for the new Self Admin

Web Forms ASP.NET. 2/12/2018 EC512 - Prof. Skinner 1

Entity framework 6 without nuget. Entity framework 6 without nuget.zip

Assessment Environment - Overview

Guide Workflow Engine.NET

Interface (API) Design

Detail Design Specification

PROGRAMMING ASP NET MVC 4

SUSE Linux Enterprise Mono Extension

CSC 415 ONLINE PHOTOALBUM: THE SEQUEL ASP.NET VERSION

10264A CS: Developing Web Applications with Microsoft Visual Studio 2010

EM L23 - Implementing Client and Server Management with Site Services Hands-On Lab

Ucommerce Masterclass. Browse + Checkout Handouts

NukaCode - Front End - Bootstrap Documentation

Transcription:

FatModel Quick Start Guide Best Practices Framework for ASP.Net MVC By Loma Consulting February 5, 2016

Table of Contents 1. What is FatModel... 3 2. Prerequisites... 4 Visual Studio and Frameworks... 4 Domain Knowledge... 4 3. Adding FatModel to a Project... 5 Simple Example... 5 Conclusion... 7 4. More Information and Help... 8 LomaCons InstallKey Quick Start Guide 2

1. What is FatModel The LomaCons FatModel framework can be added to any ASP.Net MVC based applications to enhance coding best practices and notifications to MVC models. These best practices are based on these well-known tenets of the MVC design pattern. Models should be Fat Controllers should be Skinny Views should be Dumb Additionally the FatModel framework helps to enforce these best practices and long term code consistency, by providing consistent, well named over-ridable functions and events on model objects. FatModel can be used and added to any Model and Controller, and can be used with any action result or view type, including cshtml, vbhtml, partial views, redirect, json and more. LomaCons InstallKey Quick Start Guide 3

2. Prerequisites These prerequisites are a minimum guideline for installation and are a place to start. Confirm that the following lists of prerequisites are met on the application developer systems that will be running the components of FatModel. Additional detailed installation information can be found in the FatModel Developer Guide. FatModel requires the installation and configuration of Visual Studio 2012 or newer and ASP.Net MVC 5 or newer components and features. If you are already building applications with ASP.Net MVC, then you are ready to get started. Visual Studio and Frameworks The features below are typically installed along with Visual Studio or can be pulled in via NuGet packages. The versions listed are the current stable and minimum supported versions by Microsoft at the time that the provided assemblies and documentation was last updated. Visual Studio 2012, 2013 or 2015.Net Framework 4.5.2 or later ASP.Net MVC 5.2.3 or later In general, if you are already developing applications with Visual Studio and the current release of ASP.Net MVC, these components are likely already installed. Slightly earlier versions are also supported with the source code edition of FatModel. The code for FatModel will work unchanged with any version of.net Framework 4.x.x and ASP.Net MVC 5.x.x. To support these versions, you will need to rebuild the FatModel source code targeting the appropriate framework and referencing the proper assemblies. Please note that support for.net4.5.2 or later is not included with Visual Studio 2012, but it can be added. Please contact Microsoft for more information about how to install support for version of the.net framework you are targeting. Domain Knowledge The biggest prerequisite for FatModel is a good understanding of Visual Studio, C# or VB.Net, ASP.Net MVC, HTML and other web applications in general. FatModel is easy to work with and in depth knowledge of ASP.Net MVC is not required. However, if you are just getting started with web development, and have already worked though some of the basic samples provided by Microsoft on getting started with ASP.Net MVC, you should be ready for FatModel. LomaCons InstallKey Quick Start Guide 4

3. Adding FatModel to a Project Follow the steps below to add FatModel to any ASP.Net MVC application. FatModel can be added to an existing project or a new project. The derived class objects and over-ridable methods and events need only be added to your code where you want to utilize FatModel. Simple Example The following is an example of how to use FatModel with a data entry form. The controller, model and view handles both the initial Get request of the page as well as all Post requests of the form content. This example shows how to add FatModel to your projects, and does not show all the methods and functionality in FatModel. For complete information and full API documentation, please see the Developer Guide documentation. 1. Add a reference to the LomaCons.FatModel.Mvc.dll assembly to your web application project. 2. Initialize the FatModel binder in the ASP.Net application startup code. FatModelConfig.RegisterBinder(); 3. Derive a controller from SkinnyControllerBase. Normally, you would derive from Controller. However, SkinnyControllerBase is derived from the Controller as well, so is easy to insert it into your controller class hierarchy. public class PersonController : SkinnyControllerBase { public PersonController() : base() {... 4. Derive a model from FatModelBase. You may already have a base class for your models, if so, it is easy to insert it into your controller class hierarchy. Your code will not directly create this model. Rather, the FatModel framework will look for a Model that matches this signature and FatModel will create the model, passing to the base class a reference to the controller. public class PersonCreateModel : FatModelBase { public PersonCreateModel(ISkinnyController controller) : base(controller) {... 5. Create a GET and POST controller action in your controller. The Get creates an instance of the model, using the CreateFatModel method, and returns the model to the view as a View Result. The Post will redisplay the View if there are any server side validation errors; if there are no errors then the Post will use a Redirect Action to redirect to another page. LomaCons InstallKey Quick Start Guide 5

[HttpGet] public ActionResult Create() { PersonCreateModel m; m = base.createfatmodel<personcreatemodel>(); return (View(m)); [HttpPost] public ActionResult Create(PersonCreateModel model) { if (ModelState.IsValid == false) return (View(model)); return (RedirectToAction("Samples", "Home")); 6. Override the FatModel notification methods in your model. In the example below, The Load override is responsible for loading initial model values on the Get, and will persist the changes on the Post if the model is valid. The Validate override will perform server side validation, and utilizes the MVC ModelState object to add model errors to be displayed in the view. protected override void OnLoad() { base.onload(); if (IsPostBack == true){ if (ModelState.IsValid){ _business.createperson(firstname, LastName, Age); FirstName = string.empty; LastName = string.empty; protected override void OnValidate() { base.onvalidate(); if (_business.getperson(firstname, LastName)!= null) ModelState.AddModelError("Failure", "A Person with this First Name and Last Name already exisits."); 7. Create an MVC View with a form, data entry controls, validation and a submit button. The code sample below uses C# Razor, however any view engine can be used. Note that there is nothing revolutionary or different about the view. FatModel extends and enhances only the Controllers and Models, so everything you know already about creating and manipulating views and action results does not change. LomaCons InstallKey Quick Start Guide 6

@model PersonCreateModel @using (Html.BeginForm()) { <fieldset> <div class="row"> @Html.ValidationSummary(false, null, new { @class = "text-danger" ) <div class="form-group col-md-6"> @Html.LabelFor(model => model.firstname, htmlattributes: new { @class = "control-label" ) @Html.EditorFor(model => model.firstname, new { htmlattributes = new { @class = "form-control" ) <div class="form-group col-md-6"> @Html.LabelFor(model => model.lastname, htmlattributes: new { @class = "control-label" ) @Html.EditorFor(model => model.lastname, new { htmlattributes = new { @class = "form-control" ) <div class="form-group"> <div class="col-md-12"> <div class="pull-right"> @Html.ActionLink("Cancel", "Samples", "Home", null, new { @class = "btn btn-link" ) <input type="submit" value="create Person" class="btn btn-success" /> </fieldset> A complete working example of this code and additional examples of other FatModel methods and functions can be found in the included FatModel Web Sample. 8. Build and run your application. Conclusion From a code perspective, compare this to some of the other controllers and models that you have seen or coded. You should see this. The Controller has become skinny, where it handles only the incoming request and quickly returns the proper action result. Little to no business layer interaction is needed. The Model has become fat, where it handles the interaction with the business layer, server side validation and data properties to be displayed by the view. The View remains dumb, where it only reads and display the data properties from the view. Note that the view, does not change data in the model and it does not interact with the business layer. Business Layer Interaction In the example above, you might notice that all interaction with the business layer (the layer that reads and writes content to/from the data storage repository) occurs within the Model and no business layer calls are made from within the Controller. It is neither right nor wrong to have all business layer calls in the model, all in the controller or in both. Where you call your business layer is entirely up to you and what you feel should be your best practice. Therefore, FatModel does not enforce where your business layer calls occur. See the included WebSample project for examples of both methodologies. LomaCons InstallKey Quick Start Guide 7

4. More Information and Help More detailed and complete information can be found in the FatModelDevGuide.pdf documentation. Other answers to frequently asked questions can be found on the FAQ page on the www.lomacons.com website. LomaCons InstallKey Quick Start Guide 8