zoukankan      html  css  js  c++  java
  • Pro Aspnet MVC 4读书笔记(5)

    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; }
        }
    }
    View Code

    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);
            }
        }
    }
    View Code

    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);
            }
        }
    }
    View Code

    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();
            }
    
        }
    }
    View Code
  • 相关阅读:
    Linux中的samba服务和ftp服务
    Linux中的rpm和yum软件管理
    Linux网络和进程管理
    在jupyter notebook 中编辑公式
    CEO的作用
    如何学习
    敏捷宣言遵循的原则
    敏捷宣言
    python模糊匹配之fuzzywuzzy
    拥抱变革(More Fearless Change)
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3529726.html
Copyright © 2011-2022 走看看