Pro Aspnet MVC 4读书笔记(5) - Essential Tools for MVC
Listing 6-1. The Product Model Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace EssentialTools.Models
{
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string Category { set; get; }
}
}
Listing 6-2. The LinqValueCalculator Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace EssentialTools.Models
{
public class LinqValueCalculator
{
public decimal ValueProducts(IEnumerable<Product> products)
{
return products.Sum(p => p.Price);
}
}
}
Listing 6-3. The ShoppingCart Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace EssentialTools.Models
{
public class ShoppingCart
{
private LinqValueCalculator _calculator; public ShoppingCart(LinqValueCalculator calculator)
{
_calculator = calculator;
} public IEnumerable<Product> Products { get; set; } public decimal CalculateProductTotal()
{
return _calculator.ValueProducts(Products);
}
}
}
Listing 6-4. The Home controller#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace EssentialTools.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
} }
}
Pro Aspnet MVC 4读书笔记(5) - Essential Tools for MVC的更多相关文章
- Pro Aspnet MVC 4读书笔记(3) - Essential Language Features
Listing 4-1. The Initial Content of the Home Controller using System; using System.Collections.Gener ...
- 【Tools】Pro Git 一二章读书笔记
记得知乎以前有个问题说:如果用一天的时间学习一门技能,选什么好?里面有个说学会Git是个很不错选择,今天就抽时间感受下Git的魅力吧. Pro Git (Scott Chacon) 读书笔记: ...
- [Git00] Pro Git 一二章读书笔记
记得知乎以前有个问题说:如果用一天的时间学习一门技能,选什么好?里面有个说学会Git是个很不错选择,今天就抽时间感受下Git的魅力吧. Pro Git (Scott Chacon) 读书笔记: ...
- Pro Aspnet MVC 4读书笔记(1) - Your First MVC Application
Listing 2-1. The default contents of the HomeController class using System; using System.Collections ...
- Pro Aspnet MVC 4读书笔记(4) - Working with Razor
Listing 5-1. Creating a Simple Domain Model Class using System; using System.Collections.Generic; us ...
- Pro Aspnet MVC 4读书笔记(2) - The MVC Pattern
Listing 3-1. The C# Auction Domain Model using System; using System.Collections.Generic; using Syste ...
- 《Pro Android Graphics》读书笔记之第四节
Android Procedural Animation: : XML, Concepts and Optimization Procedural Animation Concepts: Tweens ...
- 《Pro Android Graphics》读书笔记之第三节
Android Frame Animation: XML, Concepts and Optimization Frame Animation Concepts: Cels, Framerate, a ...
- 《Pro Android Graphics》读书笔记之第六节
Android UI Layouts: Graphics Design Using the ViewGroup Class Android ViewGroup Superclass: A Founda ...
随机推荐
- Routeros 计划任务连线/断线ADSL
老板吩咐,要求晚上11点前断网,目的是让大家伙早睡早起. 不想使用Panabit来做策略,阿童木的D2500C还是性能不足,就用ROS的计划任务. 第1步 校时 时间要准,要不控制个乱七八糟. 操作路 ...
- DOMContentLoaded和window.onload
相信写js的.都知道window.onload吧,可是并非每一个人都知道DOMContentLoaded,事实上即使你不知道.非常有可能你也常常使用了这个东西. 普通情况下,DOMContentLoa ...
- springmvc如何访问静态文件,例如jpg,js,css
你怎么DispatcherServlet拦截"*.do"这有一个后缀URL.就不存在訪问不到静态资源的问题. 假设你的DispatcherServlet拦截"/&qu ...
- 记View跨界平局
<?xml version="1.0" encoding="utf-8"? > <RelativeLayout xmlns:android=& ...
- QT 4.7.6 驱动 罗技C720摄像头
编译器: mingw32 gcc 4.8.1 mingw32 g++ 4.8.1 QT 版本: 4.8.6 OpenCV版本: 3.0.0 测试平台: win7 x64 --------------- ...
- Windows Phone 8 - 建立App专属联络人资讯(ContactStore)
原文:Windows Phone 8 - 建立App专属联络人资讯(ContactStore) 在WP7的时候介绍了如何操作联络人的功能,例如:<Windows Phone 7 - 存取联络人与 ...
- 在Linux上安装Hadoop
先决条件: Hadoop是用JAVA写的,所以首先要安装Java.在Ubuntu上安装JDK见:http://blog.csdn.net/microfhu/article/details/766739 ...
- android判断是否含有某权限
boolean has_permission = (PackageManager.PERMISSION_GRANTED == pkm.checkPermission("android.per ...
- CAS实现SSO单点登录原理(转)
1. CAS 简介 1.1. What is CAS ? CAS ( Central Authentication Service ) 是 Yale 大学发起的一个企业级的.开源的项目,旨 ...
- WebService 用户名密码验证
原文:WebService 用户名密码验证 在项目开发的过程中,WebService是经常要用的,当调用WebService方法时,需要经过服务的验证才可以调用,一般就是用户名/密码验证,还有一个就是 ...