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 ...
随机推荐
- 【网络可靠版】Extjs4 Treegrid 使用实例
最近调试EXTJS 4的treegrid实例,看了很多水友的文章,以及官方的demo, 没一个可靠的,全都无法显示出来.像对于我们习惯用C++的coder来说,EXTJS简直就是一群无政府土匪来维护的 ...
- DIY.NETORM帧——技术储备(1)Attribute
1.他是什么 ? 首先.我们当然Attribute它是一类,以下是一msdn文档对它的描写叙述: 公共语言执行时同意你加入类似keyword的描写叙述声明,叫做attributes, ...
- 学派Delphi方法(推荐)——————————【Badboy】
Delphi是一个新的可视化编程环境, 提供了一种方便.快捷的Windows使用顺序开发工具. 它使用了MicrosoftWindows图形用户界面的很多先进特性和设计思想. 本文就给读者引见学Del ...
- jQuery来源学习笔记:整体结构
1.1.由于调用一个匿名函数: (function( window, undefined ) { // jquery code })(window); 这是一个自调用匿名函数,第一个括号内是一个匿名函 ...
- EF 主键自增、级联删除
一.主键自增 1.设置数据库中,主键自增 2.设置VS中Model1.edmx
- js多物体任意值运动
假如有两个div,一个div要变宽,一个div要变高,你怎么写呢? 哎呀,写2个方法啊,一个控制div1变宽,一个控制div2变高啊 那么你的代码,是不是下面这样的呢! 示例:Div变宽和变高 现象: ...
- [BEROR]CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.1'
解决方法: 选择project->Build Settings -> Code Signing -> Code Signing Identity -> Debug -> ...
- sql系列(基础)-第二章 限制和排序数据
更好的看↑代码点击VIEW PLAN 第二章 约束和排序数据 1. 在 emp 表中选择工资介于 1500 到 2500 的员工的信息: 注意:使用 between 下边界 and 上边界时.条件包括 ...
- Kafka设计
[Apache Kafka]Kafka设计 在开始开发producer和consumer之前,先从设计的角度看一看Kafka. 由于重度依赖JMS,且实现方式各异.对可伸缩架构的支持不够,Link ...
- lunux命令笔记
文件查看命令 ls / -lh ls list / 路径 -l 具体 -lh 具体的人性化显示 -ld 显示文件夹 -i 显示i节点 mkdir /tmp/mulu/mulu2 /tmp/ma/mb ...