示例#1
0
        public ActionResult New(MaterialModel model)
        {
            if (ModelState.IsValid)
            {
                var material = new JL.Core.Models.Material();
                material.Title        = model.Title;
                material.MaterialType = model.FileType;
                material.Description  = model.Description;

                material.Status  = model.Status ? 0 : 1;
                material.AddTime = model.AddTime ?? DateTime.Now;

                // 生成缩略图
                if (Request.Files != null &&
                    Request.Files.Count > 0 &&
                    Request.Files[0].ContentLength > 0)
                {
                    string picture, filename;
                    var    success = FileHelper.SaveMaterial(Request.Files[0], material.MaterialType, out filename, out picture);

                    if (success)
                    {
                        material.Picture  = picture;
                        material.FileName = filename;
                        material.Url      = model.FileName;
                    }
                }

                jlService.AddMaterial(material);

                ViewData.Add("ResultObject", ResultObject.Succeed());
            }

            return(View());
        }