예제 #1
0
        private HousePicDTO ToDTO(HousePicEntity housePic)
        {
            HousePicDTO housePicDTO = new HousePicDTO();

            housePicDTO.HouseId        = housePic.HouseId;
            housePicDTO.Id             = housePic.Id;
            housePicDTO.ThumbUrl       = housePic.ThumbUrl;
            housePicDTO.Url            = housePic.Url;
            housePicDTO.CreateDateTime = housePic.CreateDateTime;
            return(housePicDTO);
        }
예제 #2
0
파일: HouseService.cs 프로젝트: zxswola/ZH
        public long AddNewHousePic(HousePicDTO housePicDTO)
        {
            HousePicEntity entity = new HousePicEntity();

            entity.HouseId  = housePicDTO.HouseId;
            entity.ThumbUrl = housePicDTO.ThumbUrl;
            entity.Url      = housePicDTO.Url;
            using (MyDbContext ctx = new MyDbContext())
            {
                ctx.HousePics.Add(entity);
                return(entity.Id);
            }
        }
예제 #3
0
 public long AddNewHousePic(HousePicDTO housePic)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         HousePicEntity housePicAdd = new HousePicEntity();
         housePicAdd.HouseId  = housePic.HouseId;
         housePicAdd.ThumbUrl = housePic.ThumbUrl;
         housePicAdd.Url      = housePic.Url;
         ctx.HousePics.Add(housePicAdd);
         ctx.SaveChanges();
         return(housePicAdd.Id);
     }
 }
예제 #4
0
 public long AddNewHousePic(HousePicDTO housePic)
 {
     using (MyDbContext dbc = new MyDbContext())
     {
         HousePicEntity pic = new HousePicEntity();
         pic.HouseId  = housePic.HouseId;
         pic.Url      = housePic.Url;
         pic.ThumbUrl = housePic.ThumbUrl;
         dbc.HousePics.Add(pic);
         dbc.SaveChanges();
         return(pic.Id);
     }
 }
예제 #5
0
 public long AddNewHousePic(HousePicDTO housePic)
 {
     using (RhDbContext ctx = new RhDbContext())
     {
         HousePicEntity housePicEntity = new HousePicEntity();
         housePicEntity.Url      = housePic.Url;
         housePicEntity.ThumbUrl = housePic.ThumbUrl;
         housePicEntity.HouseId  = housePic.HouseId;
         ctx.HousePics.Add(housePicEntity);
         ctx.SaveChanges();
         return(housePicEntity.Id);
     }
 }
예제 #6
0
        public long AddNewHousePic(HousePicDTO housePic)
        {
            HousePicEntity entity = new HousePicEntity();

            entity.HouseId  = housePic.HouseId;
            entity.ThumbUrl = housePic.ThumbUrl;
            entity.Url      = housePic.Url;
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                ctx.HousePics.Add(entity);
                ctx.SaveChanges();
                return(entity.Id);
            }
        }
예제 #7
0
 public long AddNewHousePic(HousePicDTO housePic)
 {
     using (WarmHomeContext db = new  WarmHomeContext())
     {
         HousepicEntity entity = new HousepicEntity()
         {
             ThumbUrl = housePic.ThumbUrl,
             Url      = housePic.Url,
             HouseId  = housePic.HouseId
         };
         db.Housepics.Add(entity);
         db.SaveChanges();
         return(entity.Id);
     }
 }
예제 #8
0
 public HousePicDTO[] GetPics(long houseId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <HousePicEntity> bs = new Service.BaseService <Entities.HousePicEntity>(ctx);
         var housePics           = bs.GetAll().Where(h => h.HouseId == houseId);
         List <HousePicDTO> list = new List <HousePicDTO>();
         foreach (var housePic in housePics)
         {
             HousePicDTO dto = new HousePicDTO();
             dto.Url      = housePic.Url;
             dto.ThumbUrl = housePic.Url;
             dto.Id       = housePic.Id;
             list.Add(dto);
         }
         return(list.ToArray());
     }
 }
예제 #9
0
        public ActionResult FileUpload(long houseId, HttpPostedFileBase file)
        {
            //获取文件的后缀名
            string md5Name   = Common.CommonHelper.CalcMD5(file.InputStream);
            string extension = Path.GetExtension(file.FileName);

            string newFileName       = md5Name + extension;
            string thumbFileName     = md5Name + "_thumb" + extension;
            string watermarkFileName = md5Name + "_watermark" + extension;
            //原图文件路径
            string path = Path.Combine("/UpLoadFile", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(),
                                       DateTime.Now.Day.ToString(), newFileName);
            //缩略图文件路径
            string thumbPath = Path.Combine("/UpLoadFile", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(),
                                            DateTime.Now.Day.ToString(), thumbFileName);
            //水印文件路径
            string watermarkPath = Path.Combine("/UpLoadFile", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(),
                                                DateTime.Now.Day.ToString(), watermarkFileName);
            string fullPath          = this.HttpContext.Server.MapPath("~" + path);
            string thumbFullPath     = this.HttpContext.Server.MapPath("~" + thumbPath);
            string watermarkFullPath = this.HttpContext.Server.MapPath("~" + watermarkPath);

            //尝试创建文件夹
            new FileInfo(fullPath).Directory.Create();


            //原文件
            file.SaveAs(fullPath);

            //文件指针复位,可能在保存时指针的位置指向了最后
            file.InputStream.Position = 0;
            //缩略图
            ImageProcessingJob jobThumb = new ImageProcessingJob();

            jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));
            jobThumb.SaveProcessedImageToFileSystem(file.InputStream, thumbFullPath);

            //文件指针复位,可能在保存时指针的位置指向了最后
            file.InputStream.Position = 0;
            //水印
            ImageWatermark imgWatermark = new ImageWatermark(HttpContext.Server.MapPath("~/images/watermark.png"));

            imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置
            imgWatermark.Alpha            = 50;                                          //透明度,需要水印图片是背景透明的 png 图片
            ImageProcessingJob jobNormal = new ImageProcessingJob();

            jobNormal.Filters.Add(imgWatermark);                        //添加水印
            jobNormal.Filters.Add(new FixedResizeConstraint(600, 600)); //限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个 Filter
            jobNormal.SaveProcessedImageToFileSystem(file.InputStream, watermarkFullPath);

            HousePicDTO housePic = new HousePicDTO();

            housePic.HouseId  = houseId;
            housePic.ThumbUrl = thumbPath;
            housePic.Url      = path;
            HousePicService.AddNewHousePic(housePic);


            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }
예제 #10
0
 public void UpdateHousePic(HousePicDTO housePic)
 {
     throw new NotImplementedException();
 }