コード例 #1
0
		public bool Delete(ResourceEntity entity)
		{
			try
            {
                _resourceRepository.Delete(entity);
                return true;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return false;
            }
		}
コード例 #2
0
		public ResourceEntity Update (ResourceEntity entity)
		{
			try
            {
                _resourceRepository.Update(entity);
                return entity;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return null;
            }
		}
コード例 #3
0
        public async Task<HttpResponseMessage> Upload()
        {
            var streamProvider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(streamProvider);
            var fileNames = new List<string>();
            foreach (var item in streamProvider.Contents)
            {
                if (item.Headers.ContentDisposition.FileName != null)
                {
                    var ms = item.ReadAsStreamAsync().Result;

                    //double size = ms.Length/1024;
                    //int maxSize = 50;
                    //int maxWidth = 640;
                    //int maxHeight = 200;
                    //if (size > maxSize)
                    //{
                    //Image img = Image.FromStream(ms);
                    //    int imgWidth = img.Width;
                    //    int imgHeight = img.Height;
                    //    if (imgWidth > imgHeight)
                    //    {
                    //        if (imgWidth > maxWidth)
                    //        {
                    //            float toImgWidth = maxWidth;
                    //            //float toImgHeight = imgHeight / (imgWidth / toImgWidth);
                    //            // float toImgHeight = toImgWidth*imgHeight/imgWidth;
                    //            float toImgHeight = imgHeight * (toImgWidth / imgWidth);
                    //            // Bitmap newImg=new Bitmap(img,int.Parse(toImgWidth.ToString()),int.Parse(toImgHeight.ToString()));
                    //            Bitmap newImg = new Bitmap(img, Convert.ToInt16(toImgWidth), Convert.ToInt16(toImgHeight));

                    //            MemoryStream stream = new MemoryStream();
                    //            //newImg.Save(stream, newImg.RawFormat);                               
                    //            newImg.Save(stream, ImageFormat.Png);
                    //            ms = stream;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (imgHeight > maxHeight)
                    //        {
                    //            float toImgHeight = maxHeight;
                    //            float toImgWidth = imgWidth / (imgHeight / toImgHeight);
                    //            var newImg = new Bitmap(img, int.Parse(toImgWidth.ToString()), int.Parse(toImgHeight.ToString()));
                    //            MemoryStream stream = new MemoryStream();
                    //            newImg.Save(stream, newImg.RawFormat);
                    //            ms = stream;
                    //        }
                    //    }

                    //}
                    var fileLength = ms.Length;
                    var info = new FileInfo(item.Headers.ContentDisposition.FileName.Replace("\"", ""));
                    //var allowFomat = new[] {".png",".jpg",".jepg",".gif"};
                    //var isImage = allowFomat.Contains(info.Extension.ToLower());
                    var fileNewName = GetUniquelyString();

                    //保存至OSS
                    var key = OssHelper.PutObject(ms, fileNewName + info.Extension);
                    //if (isImage)
                    //{
                    //    OssHelper.PutThumbnaiObject(ms, fileNewName + info.Extension);
                    //}

                    var resource = new ResourceEntity
                    {
                        Guid = Guid.NewGuid(),
                        Name = fileNewName,
                        Length = fileLength,
                        Type = info.Extension.Substring(1).ToLower(),
                      //  Adduser = ((UserBase)_workContent.CurrentUser).Id,
                        Addtime = DateTime.Now,
                      //  UpdUser = _workContent.CurrentUser.Id,
                        UpdTime = DateTime.Now,
                    };
                    if (_resourceService.Create(resource).Id > 0)
                        fileNames.Add(key);
                }
            }
            return PageHelper.toJson(PageHelper.ReturnValue(true, string.Join("|", fileNames)));
        }