zoukankan      html  css  js  c++  java
  • MVC Music Store 在线音乐商店示例分析(9)HomeController

    HomeController 非常简单,就是呈现首页。

    其中GetTopSellingAlbums用于检索指定数量的按照销售量排序的相册信息。

    注释后代码如下:

    1 /// <summary>
    2 /// 首页控制器
    3 /// </summary>
    4   public class HomeController : Controller
    5 {
    6 //
    7 // GET: /Home/
    8 /// <summary>
    9 /// 音乐商店实体
    10 /// </summary>
    11 MusicStoreEntities storeDB = new MusicStoreEntities();
    12
    13 /// <summary>
    14 /// Index 用于呈现音乐集列表页面
    15 /// </summary>
    16 /// <returns></returns>
    17 public ActionResult Index()
    18 {
    19 // Get most popular albums
    20 // 获取流行音乐相片集
    21 var albums = GetTopSellingAlbums(5);
    22
    23 return View(albums);
    24 }
    25
    26 /// <summary>
    27 /// 返回指定数目的,按照流行程度排序的,音乐照片集列表
    28 /// 私有方法,不被控制器外部访问
    29 /// </summary>
    30 /// <param name="count">获取指定数目</param>
    31 /// <returns>返回该指定数目下的音乐照片集</returns>
    32 private List<Album> GetTopSellingAlbums(int count)
    33 {
    34 // Group the order details by album and return
    35 // the albums with the highest count
    36 ///通过订单详情中购买量多少的为搜寻排序条件找出流行的音乐相片集
    37 return storeDB.Albums
    38 .OrderByDescending(a => a.OrderDetails.Count())
    39 .Take(count)
    40 .ToList();
    41 }
    42 }
  • 相关阅读:
    C++中的静态数据成员的作用与好处
    C++中的虚函数表
    CF292-D
    CF292-C
    CF292-B
    CF292-A
    CF291-B
    CF291-C
    CF287-B
    CF287-C
  • 原文地址:https://www.cnblogs.com/stevenhqq/p/1971574.html
Copyright © 2011-2022 走看看