public IHttpActionResult SaveVersion([FromBody] TD_ModifyProductVersion model)
        {
            DataBaseEntities db = new DataBaseEntities();
            var data = db.pm_ProductVersion.Single(u => u.RecordId == model.versionid);
            data.RecordContent = model.content;
            db.SaveChanges();

            var data1 = db.pm_ProductVersion.Where(u => u.ProductId == model.productid).OrderByDescending(u => u.TestVersion).ToList().Select(u => new
            {
                u.TestVersion,
                AddDate = u.AddDate.ToShortDateString(),
                u.RecordContent,
                u.RecordId,
                u.ProductId

            });
            return Json(new
            {
                Code = 10000,
                Detail = data1,

            });


        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public async Task<IHttpActionResult> Post()
        {

              //如果不含文件就退出
            if (!HttpContext.Current.Request.Files.AllKeys.Any())
            {
                return Json(new
                {
                    Code = 1
                });
            }
           
            var httpPostedFile = HttpContext.Current.Request.Files[0];
            if (httpPostedFile == null)
            {
                return Json(new
                {
                    Code = 1
                });
            }
            BlobHelper blob = new BlobHelper(BlobString.Portrait);
            string fileName = Guid.NewGuid().ToString();
            blob.Upload( httpPostedFile, fileName);
            bool isPicture = false;
           
            switch(httpPostedFile.ContentType)
            {
                case  "image/jpeg": 
                case  "image/png":
                    isPicture = true;

                    break;
                 

                default:
                    break;
            }
            //插入数据库,如果是图像文件,生成缩略图,大图
            DataBaseEntities db = new DataBaseEntities();
            pm_Attach attach = new pm_Attach
            {
                AddDate = DateTime.Now,
                AttachId = Guid.NewGuid().ToString(),
                ContentType = httpPostedFile.ContentType,
                IsPicture = isPicture,
                VersionId = HttpContext.Current.Request.Form["versionid"],
                Url = "http://hdy.awblob.com/portrait/" + fileName,
                 DisplayName = httpPostedFile.FileName
            };
            db.pm_Attach.Add(attach);
            db.SaveChanges();

            if (isPicture)
            {
                string fileSaveName = Guid.NewGuid() + ".jpg";
                var fileOrginalFile = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload"), fileSaveName);
                httpPostedFile.SaveAs(fileOrginalFile);

                string fileResized300Name = HttpContext.Current.Server.MapPath("~/upload/" + Guid.NewGuid().ToString() + ".jpg");
                using (var imageFactory = new ImageFactory(preserveExifData: true))
                {

                    System.Drawing.Size size = new System.Drawing.Size(300, 300);
                    ResizeLayer resize = new ResizeLayer(size, ResizeMode.Crop);
                    imageFactory.Load(fileOrginalFile).Resize(resize).Save(fileResized300Name);
                }
                await blob.UploadFile(fileResized300Name, fileName+"-preview", httpPostedFile.ContentType);

                string fileResizedBigName = HttpContext.Current.Server.MapPath("~/upload/" + Guid.NewGuid().ToString() + ".jpg");
                using (var imageFactory = new ImageFactory(preserveExifData: true))
                {

                    System.Drawing.Size size = new System.Drawing.Size(800, 1600);
                    ResizeLayer resize = new ResizeLayer(size, ResizeMode.Max);
                    imageFactory.Load(fileOrginalFile).Resize(resize).Save(fileResizedBigName);
                }

                await blob.UploadFile(fileResizedBigName, fileName + "-big", httpPostedFile.ContentType);

            }

           



           


            // Get the uploaded image from the Files collection




            return Json(new
            {
                Code = 10000,
                Detail = "http://hdy.awblob.com/portrait/" + fileName
            });

        }
        public IHttpActionResult versionlist([FromBody] TD_ProductVersion model)
        {
            DataBaseEntities db = new DataBaseEntities();
            var currentversion = db.pm_ProductVersion.Where(u => u.ProductId == model.productid).OrderByDescending(u => u.TestVersion).FirstOrDefault();
            int newVersion = 1;
            if (currentversion != null)
            {
                newVersion = currentversion.TestVersion + 1;
            }
            pm_ProductVersion version = new pm_ProductVersion
             {
                 AddDate = DateTime.Now,
                 ProductId = model.productid,
                 TestVersion = newVersion,
                 RecordContent = model.content,
                 RecordId = Guid.NewGuid().ToString()
             };
            db.pm_ProductVersion.Add(version);
            db.SaveChanges();
            var data = db.pm_ProductVersion.Where(u => u.ProductId == model.productid).OrderByDescending(u => u.TestVersion).ToList().Select(u => new
            {
                u.TestVersion,
                AddDate = u.AddDate.ToShortDateString(),
                u.RecordContent,
                u.RecordId,
                u.ProductId

            });
            return Json(new
            {
                Code = 10000,
                Detail = data,

            });


        }