种子列表

写在前面

上篇文章实现了视频列表,本篇文章继续实现其他的文件列表。功能相似。这里就不再赘述。

实现

同样根据文件类型的图片来获取种子文件列表。

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
{
    /// <summary>
    /// 种子
    /// </summary>
    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<DateTime>(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<MyFileViewModel> lstMyFileViewModel = new List<MyFileViewModel>();
            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";
}


<script>

    $(function () {
        var imgElement = $('#docmentpage');
        var options = {
            size: "large",
            bootstrapMajorVersion: 3,
            //当前页
            currentPage: 1,
            //可以改变显示的页码数
            numberOfPages: 5,
            //总页数
            totalPages: 5
        };
        function requestServer(pageIndex) {
            $.getJSON('/Torrent/GetTorrents?page=' + pageIndex, function (data) {
                console.log(data);
                data = JSON.parse(data);
                if (data.total <= pageIndex) {
                    options.totalPages = pageIndex;
                } else {
                    options.totalPages = data.total;
                };

                $('#dvdocument').html('');
                $('<table class="table table-bordered table-hover table-striped table-top" id="tbdocument"><tr><th>文件名</th> <th>文件大小</th><th>创建时间</th> </tr></table>').appendTo($('#dvdocument'));;
                for (var i = 0; i < data._data.length; i++) {
                    var current = data._data[i];
                    $('<tr><td data-id=' + current.Id + '><img src="' + current.FileIcon + '">' + current.Name + '</td><td>' + current.Size + '</td><td>' + ChangeDateFormat(current.Dt) + '</td></tr>').appendTo($('#tbdocument'));
                };
                imgElement.bootstrapPaginator(options);

            });
        };
        function loadData(pageIndex) {

            options.onPageClicked = function (e, originalEvent, type, page) {
                //页码单击事件
                console.log(page);
                options.currentPage = page;

                requestServer(page);

            };
            requestServer(pageIndex);
            imgElement.bootstrapPaginator(options);

        };

        loadData(1);
    });
</script>
<div class="tableContent" style="width:95%;" id="dvdocument">

</div>
<div style="width:95%;position:relative;margin-top:10px">
    <ul id='docmentpage' class="bjui-pageFooter" style="margin:0 auto; margin-left:30%;"></ul>
</div>

测试

总结

列表实现,没什么好说的,超级简单。