Example #1
0
        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="guid">文件组唯一标示</param>
        /// <param name="score">文件上传来源</param>
        /// <param name="userid">上传者</param>
        /// <returns>文件数据存储id</returns>
        public int Save(Guid guid, string score, int userid)
        {
            //目录创建
            if (!Directory.Exists(SavePath))
            {
                Directory.CreateDirectory(SavePath);
            }

            _file.SaveAs(Path.Combine(SavePath, FileInfo.FileName));
            UploadScore uploadScore;

            if (!Enum.TryParse(score, false, out uploadScore))
            {
                uploadScore = UploadScore.Other;
            }
            int attachmentid = Attachments.AddAttachment(new AttachmentInfo()
            {
                FileName    = FileInfo.FileName,
                FileTitle   = FileInfo.FileTitle,
                FileSize    = FileInfo.FileSize,
                Height      = FileInfo.Height,
                Width       = FileInfo.Width,
                Guid        = guid,
                Type        = FileInfo.FileEx,
                BType       = (int)FileInfo.FileType,
                Score       = (int)uploadScore,
                State       = (int)AttachmentState.Init,
                VirtualPath = SavePath,
                UserId      = userid
            });

            return(attachmentid);
        }
        public JsonResult Add(AttachmentVModel model)
        {
            var result = new JsonResultModel();

            if (ModelState.IsValid)
            {
                //add
                result.ResultState = Attachments.AddAttachment(Attachments.AttachmentVModelToInfo(model)) > 0;
            }
            else
            {
                result.ResultState = false;
                result.Message     = ModelStateHelper.GetAllErrorMessage(ModelState);
            }

            return(Json(result));
        }