building a mvc ecommerce site in under 5 minutes
DESCRIPTION
For those of us who have spent most of our careers building business applications, the prospect of creating an e-commerce storefront can be quite daunting. Not only do you have to deal with calculating tax, estimating shipping and accepting payments, but employees need a way to manage products, discounts and marketing content. Thankfully, there's an open source e-commerce solution written in Microsoft ASP.NET MVC named nopCommerce that provides all this functionality and much more. I was so impressed by both the functionality and the underlying architecture that I've created a presentation which I believe will serve as a great introduction to MVC as well as a tutorial on developing custom storefronts using nopCommerce. We start off with a brief overview of basic MVC concepts accompanied by examples within the nopCommerce code. This includes strongly typed Razor views, HTML helpers, jQuery ajax calls, and fluent validation. Once everyone understands how the website works, we dive into the infrastructure by introducing WCF services, using a generic repository with Entity Framework(EF4) and LINQ, as well as Dependency Injection (DI) with Automapper.TRANSCRIPT
![Page 1: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/1.jpg)
Build a MVC eCommerce Sitein Under 5 Minutes
Gaines Kergosien@gainesk
http://dotnetdude.net
Sr. Solutions Architecthttp://www.vanick.com
![Page 2: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/2.jpg)
2
What is nopCommerce? Open Source
Product Catalog Categories Products/Variants
Customer Management
Order Management Mobile Support Discounts Wish Lists Gift Cards Newsletters
Recurring Payments
Reporting Payment Methods Shipping Methods Taxes External Auth Polls News Blogs Forums Multiple Stores
![Page 3: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/3.jpg)
Why this topic?
3
Why MVC and WCF? Decoupled Scalable Reusable Maintainable
Why nopCommerce? Top eCommerce app on MS Web
Matrix Open Source (GPLv2 License)
3
![Page 4: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/4.jpg)
MVC
44
View
ModelController
![Page 5: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/5.jpg)
MVC
55
View
ModelController
![Page 6: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/6.jpg)
Models
Class that represents data
public class MyViewModel{ public string Foo { get; set; }}
![Page 7: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/7.jpg)
Models
![Page 8: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/8.jpg)
Validators
![Page 9: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/9.jpg)
MVC
99
View
ModelController
![Page 10: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/10.jpg)
Views
A view is a standard (X)HTML document that can contain scripts.
Views support ASP.NET markup or Razor Razor markup used in nopCommerce
nopCommerce views are strongly typed
![Page 11: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/11.jpg)
Views
![Page 12: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/12.jpg)
HTML Helpers
Methods which typically return string. Used to generate standard HTML
elements textboxes, dropdown lists, links etc.
Usage is optional You can create your own HTML Helpers
![Page 13: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/13.jpg)
MVC
1313
View
ModelController
![Page 14: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/14.jpg)
Controllers
Class derives from System.Web.Mvc.Controller
Generates the response to the browser requestpublic class HomeController : Controller{ public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!";
return View(); }
public ActionResult About() { return View(); }}
![Page 15: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/15.jpg)
Controller Actions
Public method of the Controller class
Cannot be overloaded or a static methodpublic class HomeController : Controller
{ public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!";
return View(); }
public ActionResult About() { return View(); }}
![Page 16: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/16.jpg)
Controllers
![Page 17: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/17.jpg)
Controller Actions
![Page 18: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/18.jpg)
Controllers
![Page 19: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/19.jpg)
Controller Actions
Get
Post
![Page 20: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/20.jpg)
Questions?
2020
View
ModelController
![Page 21: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/21.jpg)
View
ModelBrowser Controller
MVC
2121
![Page 22: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/22.jpg)
Routing
http://www.mysite.com/Home/About/6 {controller} = Home {action} = About {id} = 6
Locations for nopCommerce Nop.Web.Infrastructure.RouteProvider Nop.Web.Infrastructure.GenericUrlRoutePr
ovider
![Page 23: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/23.jpg)
Route Provider
![Page 24: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/24.jpg)
Generic URL Route Provider
![Page 25: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/25.jpg)
nopCommerce Libraries Nop.Core – Domain Objects &
Infrastructure Nop.Data – Data Access
Uses Entity Framework Maps Tables to Domain Objects
Nop.Services – Business Logic
![Page 26: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/26.jpg)
Domain Objects
![Page 27: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/27.jpg)
Domain Objects
![Page 28: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/28.jpg)
Domain Object Mapping
![Page 29: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/29.jpg)
Services
![Page 30: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/30.jpg)
Dependency Injection
![Page 31: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/31.jpg)
Generic Repositories
![Page 32: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/32.jpg)
LINQ Queries
![Page 33: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/33.jpg)
nopCommerce Plugins Loaded at runtime
Independent of core source Consume events Marketable See next session!
![Page 34: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/34.jpg)
nopCommerce Admin Site Nop.Admin project under relative
path /Admin Uses AutoMapper to link Objects
and Models
![Page 35: Building a MVC eCommerce Site in Under 5 Minutes](https://reader033.vdocuments.mx/reader033/viewer/2022061218/54b6ff3e4a795998388b457b/html5/thumbnails/35.jpg)
Contact Info
Blog: http://dotnetdude.net
Email: gaines [at] kergosien.net
Twitter: @gainesk
Rate this talk @ http://spkr8.com/t/35551