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 ...
随机推荐
- Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程
原文:Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程 Red Gate系列之二 SQL Source Co ...
- 【牛腩新闻公布系统】WebForms UnobtrusiveValidationMode 须要“jquery”ScriptResourceMapping。
问题: WebForms UnobtrusiveValidationMode须要"jquery"ScriptResourceMapping. 请加入一个名jquery ...
- [笔记] C# Windows Phone 8 WP8 开发,判断目前网路是否可用。
原文:[笔记] C# Windows Phone 8 WP8 开发,判断目前网路是否可用. 常常我们在开发Windows Phone 8 App时会使用网路来读取网页的资料或其他开放平台的Json.X ...
- Cocos2d-x项目总结中的一些遇到的问题
这几天在用Cocos2D-X尝试着做一个小游戏,当然不是创新,仅仅是单纯的模仿,就是为了将自己这段时间学到的技术应用于实践中. 在这个过程中.遇到了一些问题,在此特做一些总结,以免以后遇到类似的问题. ...
- C#读书
C#读书雷达 大家都知道,ThoughtWorks的技术雷达每年都会发布两到三次,它不但是业界技术趋势的标杆,更提供了一种卓有成效的方法论,即打造自己的技术雷达.在这种思想的驱动下,我们诞生了自己 ...
- SDL 简单入门学习
write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 讨论新闻组及文件 概要 实际学习使用SDL创建窗体,并绘制图形. 前言 今天想要做一个简单的demo ...
- HDU 1557 权利指数 国家压缩 暴力
HDU 1557 权利指数 状态压缩 暴力 ACM 题目地址:HDU 1557 权利指数 题意: 中文题,不解释. 分析: 枚举全部集合,计算集合中的和,推断集合里面的团体是否为关键团队. 代码: ...
- [Django] Base class in the model layer
In the model layer, the Model class is the base class while the ModelBase class is metaclass.
- w3wp与w3svc
如何找到w3wp与w3svc的对应关系 在生产环境中,一般会有多个IIS进程在运行,这里面可能是有Web Garden的设置,也可能是有多个application pool在运行.而我们经常在 ...
- Nginx + Lua + redis (一)(转)
使用 Lua 脚本语言操作 Redis. 由于大量的 Lua 代码写在 Nginx 中,会使配置文件显得很繁琐,所以这里使用 content_by_lua_file 来引入 Lua 脚本文件. 要使用 ...