Date post: | 20-Jan-2015 |
Category: |
Software |
Upload: | ian-carnaghan |
View: | 9,494 times |
Download: | 2 times |
Programming is FunWith ASP.NET MVC!
Ian Carnaghan
Page 2
Programming is Fun with ASP.NET MVC
Introduction to ASP.NET
What is ASP.NET?
ASP.NET is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting.
It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages (ASP) technology.
ASP.NET supports three different development models:Web Pages, MVC (Model View Controller), and Web Forms.
Page 3
ASP.NET
Visual Studio 2012
Programming is Fun with ASP.NET MVC
The ASP.NET Framework
ASP.NETWeb
Forms
ASP.NETMVC
ASP.NETWeb
Pages
Web Forms View Engine
Razor View Engine
WebMatrixWhat is ASP.NET?
Web Pages is the Simplest ASP.NET model. Similar to PHP and classic ASP with built-in templates and helpers for database, video, graphics, social media and more.
MVC separates web applications into different different components and provides a lighter weight framework, separation of concerns and DRY approach to development.
Webforms is the traditional ASP.NET event driven development model. Web pages with added server controls, server events, and server code.
Page 4
Programming is Fun with ASP.NET MVC
IISIIS SQL Server
SQL Server
EntityFramework
EntityFramework ASP.NETASP.NET JS &
JQueryJS &
JQuery
The Microsoft Web Platform
Internet Information Services is the web server used by ASP.NET applications.
EF is an Object Relational Mapper (ORM) – the layer that converts DB elements such as tables and views to objects uses in the application.
ASP.NET MVC comes with JavaScript libraries, jQuery
and HTML 5 support.
ASP.NET can use a range of databases, however SQL Server is the most popular has great support in Visual Studio.
ASP.NET is the development framework.
Page 5
Programming is Fun with ASP.NET MVC
Model View Controller
MVC
Model–view–controller (MVC) is a software architecture pattern which separates the representation of information from the user's interaction with it. It was introduced by Trygve Reenskaug at Xerox Parc in 1976.
Model represents the data and business logic such as database tables, constraints and validations.
View represent the screens the users access. The view uses data from the model to provide information to the user.
Controller handles requests sent in by the user and determines what actions need to be taken by the application.
Page 6
Programming is Fun with ASP.NET MVC
Interactions Follow Natural Cycle:1. User takes action
2. Application changes data model
3. Updated view sent to user
Different TechnologiesMVC compatible with combining
other technologies into tiers or layers.
Full Control over UINew Razor View Engine provides greater control and cleaner code.
No Viewstate requirement with auto-generated code –100s Kb smaller.
Total control over requests sent netween server and browser.
User ExperienceHTML 5 Technologies, Non-Obtrusive JS, Routing,. Maintainability
Modern coding StandardsConvention over configuration.
Similar to other popular MVC Frameworks including Grails, Ruby on Rails, Spring MVC, Monorail and many others.
MaintainablilityDRY approach to programming
TestabilitySince the UI is completely seperated from the business logic, it is easier to unit tests.
Multiple Unit testing framworks available.
Why Microsoft ASP.NET MVC?
Page 7
Programming is Fun with ASP.NET MVC
C:\Inetpub\wwwroot\Website\Person.aspx
http://www.website.com/Person.aspx?id=5
http://www.website.com/Person/5
Physical Location
ASP.NET Style
MVC Style
Routing
Routing in MVC comes packages with easy to configure rules based on different circumstances.
By default {ControllerName}/{MethodName}/(optional Id)
Many URLs can link to the same controller via different methods
Page 8
Programming is Fun with ASP.NET MVC
Code First Preferred by programmers who do not want to work with designers and EDMX. Full control (no autogenerated code). Seperation from DB, regardless of technology. The ORM will handle creation. Manual changes to DB problematic and lost since code defines the database.
Database First Best choice if you already have DB designed by DBAs. ORM creates entities for you to use in your application. Manual changes to the database are possible - update model from database
Model First Preferred by people interested in building a site with least amount of coding. Use design tools – Partial loss of control on both entities and database Can be very productive for small easy projects. Manual changes to DB problematic and lost since model defines the database.
Architectural Options for Developing an Application
Page 9
Programming is Fun with ASP.NET MVC
Person Entity:
Id (int)
FirstName (string)
LastName (string)
BirthDate (datetime)
Context:
People (Collection of Person)
Using ASP.NET DbContext library for Entity Framework
Person Model
Index Method – Call existing records from model to pass to a list view
Create Method – Provide empty model to pass to a create view and handle posts
Edit Method – Call an existing record via the model to pass to an edit view and handle posts
Details Page – Call an existing record via the model to pass to a display view
Person Controller
Person/Index
Person/Create
PersonEdit
Person/Details
Person Views
Simple CRUD (Create Read Update Delete) Application
The Object Relational Mapper enables communication between the application and database and converts database elements into application-ready objects.
ASP.NET uses Entity Framework and a .Net Library called DbContext for this process.
DbContext enables you to query a database and group together changes that will then be written back to the store as a unit.
Page 10
Programming is Fun with ASP.NET MVC
Simple CRUD (Create Read Update Delete) Application
Page 11
Programming is Fun with ASP.NET MVC
Office of Population Affairs was a legacy ColdFusion Application, which was redesigned using ASP.NET and launched in April 2013.
Application required versioning of records, logging, approvals and extensive search.
Twitter Bootstrap was used for the frontend layout providing a responsive HTML 5 compliant design.
Solr libraries integrated with ASP.NET via SolrNET.
MVC 4 using Code First Entify Framework Implementation with SQL Server and IIS.
Office of Population Affairs
Bootstrap
Apache Solr
ASP.NET MVC 4 & EF
Page 12
Programming is Fun with ASP.NET MVC
Domain Model Object representation of the physical database tables Validation and contraints are defined here and used throughout the
application
Repositories Heavy lifting work of performing all transactions needed from the
application layer to the database Mapping between Domain objects and View Model objects
Abstraction Layer
Interfaces the controllers can use to perform repository actions. Provides an additional layer of seperation – if major changes occur in
repository – the controllers are not dependent upon them.
View Models Subsets of the Domain Model, proving view specific information. Example public Organization Details only contains specific fields.
OPA Application Structure
Page 13
Programming is Fun with ASP.NET MVC
Community Health Online Resource Center
Ajax-based CDC Application
Resource database of records tagged in various categories.
Full-text searching and AJAX front-end for user interaction.
Back-end administration for managing resources and adding users to maintain the database.
Integration into CDC PIV Card authentication via C# Active Directory libraries.
Page 14
Programming is Fun with ASP.NET MVC
National Diabetes Education Program Application will share code-base for the CHORC Records listing with thumbnails and integration with
NDEP API for adding resources to external cart.
Monarch Academy web-based Curriculum Mapping.
CM for Expeditionary Learning
Maintainable by Administrators, Accessible by all Teachers
Based on Education Research
Future Projects
Page 15
Programming is Fun with ASP.NET MVC
http://www.pluralsight.com
Pluralsight is by and far the best Microsoft Development Training Site!
ICF may pay for the yearly subscription via Training or Tuition Reimbursement
Check out Julie Lerman
http://www.apress.com/9781430242369
Work through the Sports Store tutorial!
Great indepth explanations
Keep as good reference guide
http://www.hanselman.com
Check out his other videos at various conferences
Subscribe to Hanselminutes Podcasts
Also check out .Net Rocks!
Learning Resources for ASP.NET MVC 4
* Oh and did I mention Stackoverflow!?
Page 16
Do You Have Any Questions?