public IHttpActionResult versionlist(string product)
        {
            DataBaseEntities db = new DataBaseEntities();
            var data = db.pm_ProductVersion.Include("pm_Attach").Where(u => u.ProductId == product).OrderByDescending(u => u.TestVersion).ToList().Select(u => new
            {
                u.TestVersion,
                AddDate = u.AddDate.ToShortDateString(),
                u.RecordContent,
                u.ProductId,
                u.RecordId,
                Attach =  u.pm_Attach.OrderByDescending(g=>g.IsPicture).Select(m=>new {
                 m.DisplayName,
                 m.Url,
                 m.IsPicture,
                 m.ContentType
                
                }),
                HasAttach = u.pm_Attach.Count() != 0

            });
            var obj = db.pm_Product.Include("pm_Project").Single(u => u.ProductId == product);
            return Json(new
            {
                Code = 10000,
                Detail = data,
                Project = obj.ProductName + " - " + obj.pm_Project.ProjectName
            });
        }
        public IHttpActionResult all()
        {
            DataBaseEntities db = new DataBaseEntities();
            var data = db.pm_Project.Include("pm_Product").Select(u => new
            {

                u.ProjectId,
                u.ProjectName,
                Count = u.pm_Product.Count()
            });
            return Json(new
           {
               Code = 10000,
               Detail = data
           });
        }
 public IHttpActionResult list(string project)
 {
     DataBaseEntities db = new DataBaseEntities();
     var data = db.pm_Product.Include("pm_ProductVersion").Where(u => u.ProjectId == project).Select(u => new
     {
         u.ProductId,
         u.ProductName,
         u.ProjectId,
         Count = u.pm_ProductVersion.Count
     });
     string projectName = db.pm_Project.Single(u => u.ProjectId == project).ProjectName;
     return Json(new
     {
         Code = 10000,
         Detail = data,
         Project = projectName
     });
 }
        /// <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 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,

            });


        }
        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,

            });


        }