时间:2021-07-01 10:21:17 帮助过:3人阅读
服务端代码
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 DocumentController : Controller { 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 GetDocuments() { 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("DocType.png") || x.FileIcon.Contains("XlsType.png") || x.FileIcon.Contains("PptType.png") || x.FileIcon.Contains("PdfType.png") || x.FileIcon.Contains("TxtType.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 }; } } }
测试
实现起来还是比较简单的,马上就2016年了,祝大家元旦快乐。
[实战]MVC5+EF6+MySql企业网盘实战(23)——文档列表
标签: