写在前面
上篇文章实现了视频列表,本篇文章继续实现其他的文件列表。功能相似。这里就不再赘述。
系列文章
[实战]MVC5+EF6+MySql企业网盘实战(25)——种子列表
实现
同样根据文件类型的图片来获取种子文件列表。
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Script.Serialization;using Wolfy.NetDisk.BLL;using Wolfy.NetDisk.IBLL;using Wolfy.NetDisk.Model;using Wolfy.NetDisk.Site.Models;namespace Wolfy.NetDisk.Site.Controllers{ ////// 种子 /// public class TorrentController : Controller { // // GET: /Videos/ private IMyFileServiceRepository _myFileServiceRepository = new MyFileServiceRepository(); private ILogServiceRepository _logServiceRepository = new LogServiceRepository(); private IFileTypeServiceRepository fileTypeServiceRepository = new FileTypeServiceRepository(); // // GET: /Images/ public ActionResult Lists() { UserInfo user = Session["user"] as UserInfo; if (user == null) { return RedirectToAction("Login", "UserInfo"); } return View(); } [HttpGet] public JsonResult GetTorrents() { UserInfo userInfo = Session["user"] as UserInfo; int page = Convert.ToInt32(Request.Params["page"]); if (page <= 0) { page = 1; } if (userInfo == null) { RedirectToAction("Login", "UserInfo"); } int pageSize = 10; int recordCount = 0; var documentPaged = _myFileServiceRepository.FindPaged(page, pageSize, out recordCount, x => x.User.Id == userInfo.Id && x.IsDelete == false && (x.FileIcon.Contains("TorrentType.png")), false, x => x.CreateDt); int totalPage = Convert.ToInt32(Math.Ceiling(recordCount * 1.0 / pageSize)); List lstMyFileViewModel = new List (); foreach (var item in documentPaged) { lstMyFileViewModel.Add(new MyFileViewModel() { Id = item.Id, FileIcon = item.FileIcon, FileServerUrl = "/NetDisk/" + item.FileMd5 + item.FileExt, Name = item.Name, FileThumnailUrl = string.Empty, Size = item.FileSize, Dt = item.CreateDt }); } return new JsonResult() { Data = new JavaScriptSerializer().Serialize(new { _data = lstMyFileViewModel, _code = 200, total = totalPage }), JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } }}
前端
@{ ViewBag.Title = "Lists"; Layout = "~/Views/Shared/_Layout.cshtml";}
测试
总结
列表实现,没什么好说的,超级简单。