首页 > Web开发 > 详细

Pro Aspnet MVC 4读书笔记(5) - Essential Tools for MVC

时间:2014-01-22 18:23:50      阅读:437      评论:0      收藏:0      [点我收藏+]

Listing 6-1. The Product Model Class

bubuko.com,布布扣
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; }
    }
}
View Code

Listing 6-2. The LinqValueCalculator Class

bubuko.com,布布扣
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);
        }
    }
}
View Code

Listing 6-3. The ShoppingCart Class

bubuko.com,布布扣
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);
        }
    }
}
View Code

Pro Aspnet MVC 4读书笔记(5) - Essential Tools for MVC

原文:http://www.cnblogs.com/thlzhf/p/3529726.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!