Exemple #1
0
        /// <summary>
        /// 附件管理列表
        /// </summary>
        /// <param name="id">公共模型ID</param>
        /// <param name="dir">目录(类型)</param>
        /// <returns></returns>
        public ActionResult FileManagerJson(int?id, string dir)
        {
            Models.AttachmentManagerViewModel _attachmentManagerViewModel;
            IQueryable <Attachment>           _attachments;

            // id 为null,表示是公共模型id为null,此时查询数据库中没有跟模型对应起来的附件列表(以上传,但上传的文章还未保存)
            if (id == null)
            {
                _attachments = attachmentService.FindList(null, User.Identity.Name, dir);
            }
            else
            {
                _attachments = attachmentService.FindList((int)id, User.Identity.Name, dir, true);
            }
            // 循环构造AttachmentMangerViewModel
            var _attachmentList = new List <Models.AttachmentManagerViewModel>(_attachments.Count());

            foreach (var _attachment in _attachments)
            {
                _attachmentManagerViewModel = new Models.AttachmentManagerViewModel()
                {
                    datetime = _attachment.UploadDate.ToString("yyyy-MM-dd HH:mm:ss"), filetype = _attachment.Extension, has_file = false, is_dir = false, is_photo = _attachment.Type.ToLower() == "image"? true:false, filename = Url.Content(_attachment.FileParth)
                };
                FileInfo _fileInfo = new FileInfo(Server.MapPath(_attachment.FileParth));
                _attachmentManagerViewModel.filesize = (int)_fileInfo.Length;
                _attachmentList.Add(_attachmentManagerViewModel);
            }
            return(Json(new { moveup_dir_path = "", current_dir_path = "", current_url = "", total_count = _attachmentList.Count(), file_list = _attachmentList }, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// 附件管理列表
 /// </summary>
 /// <param name="id">公共模型ID</param>
 /// <param name="dir">目录(类型)</param>
 /// <returns></returns>
 public ActionResult FileManagerJson(int? id, string dir)
 {
     Models.AttachmentManagerViewModel _attachmentViewModel;
     IQueryable<Attachment> _attachments;
     //id为null,表示是公共模型id为null,此时查询数据库中没有跟模型对应起来的附件列表(以上传,但上传的文章……还未保存)
     if (id == null) _attachments = attachmentService.FindList(null, User.Identity.Name, dir);
     //id不为null,返回指定模型id和id为null(新上传的)附件了列表
     else _attachments = attachmentService.FindList((int)id, User.Identity.Name, dir, true);
     //循环构造AttachmentManagerViewModel
     var _attachmentList = new List<Models.AttachmentManagerViewModel>(_attachments.Count());
     foreach (var _attachment in _attachments)
     {
         _attachmentViewModel = new Models.AttachmentManagerViewModel() { datetime = _attachment.UploadDate.ToString("yyyy-MM-dd HH:mm:ss"), filetype = _attachment.Extension, has_file = false, is_dir = false, is_photo = _attachment.Type.ToLower() == "image" ? true : false, filename = Url.Content(_attachment.FileParth) };
         FileInfo _fileInfo = new FileInfo(Server.MapPath(_attachment.FileParth));
         _attachmentViewModel.filesize = (int)_fileInfo.Length;
         _attachmentList.Add(_attachmentViewModel);
     }
     return Json(new { moveup_dir_path = "", current_dir_path = "", current_url = "", total_count = _attachmentList.Count, file_list = _attachmentList }, JsonRequestBehavior.AllowGet);
 }