Пример #1
0
        private void CreateStaticPage(long houseId)
        {
            HouseIndexViewModel houseIndexView = null;

            HouseDTO house = HouseService.GetById(houseId);

            if (house == null)
            {
                return;
            }

            var housePics   = HousePicService.GetPics(houseId);
            var attachments = AttachmentService.GetAttachment(houseId);

            houseIndexView = new HouseIndexViewModel
            {
                House       = house,
                HousePics   = housePics,
                Attachments = attachments
            };
            this.ControllerContext.Controller.ViewData.Model = houseIndexView;
            string html = WebCommonHelper.RendViewToString(
                this.ControllerContext,
                "~/views/House/StaticIndex.cshtml",
                "");

            System.IO.File.AppendAllText(String.Format(@"D:\PersonalWorkSpace\github\ZSZ\ZSZ.FrontWeb\{0}.html", houseId), html);
        }
Пример #2
0
        public ActionResult HousePicList(long houseId)
        {
            var housePics = HousePicService.GetPics(houseId);

            ViewBag.HouseId = houseId;
            return(View(housePics));
        }
Пример #3
0
        public ActionResult HousePicBatchDelete(long[] seletcedIds)
        {
            foreach (long id in seletcedIds)
            {
                HousePicService.MarkDeleted(id);
            }

            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }
Пример #4
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"
            }));
        }
Пример #5
0
        public ActionResult Index(long id = 1)
        {
            #region Cache缓存
            //string cacheKey = "houseIndex_" + id;
            //HouseIndexViewModel houseIndexView = null;
            //if (HttpContext.Cache[cacheKey] == null)
            //{
            //    HouseDTO house = HouseService.GetById(id);
            //    if (house == null)
            //    {
            //        return View("~/Views/Shared/Error.cshtml", (object)"不存在的房源id");
            //    }

            //    var housePics = HousePicService.GetPics(id);
            //    var attachments = AttachmentService.GetAttachment(id);
            //    houseIndexView = new HouseIndexViewModel
            //    {
            //        House = house,
            //        HousePics = housePics,
            //        Attachments = attachments
            //    };


            //    HttpContext.Cache.Insert(cacheKey, houseIndexView, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
            //}
            //else
            //{
            //    houseIndexView = (HouseIndexViewModel)HttpContext.Cache[cacheKey];
            //}
            #endregion

            #region Memcached缓存



            string cacheKey = "houseIndex_" + id;



            HouseIndexViewModel houseIndexView = MemcachedMgr.Instance.GetValue <HouseIndexViewModel>(cacheKey);

            if (houseIndexView == null)
            {
                HouseDTO house = HouseService.GetById(id);
                if (house == null)
                {
                    return(View("~/Views/Shared/Error.cshtml", (object)"不存在的房源id"));
                }

                var housePics   = HousePicService.GetPics(id);
                var attachments = AttachmentService.GetAttachment(id);
                houseIndexView = new HouseIndexViewModel
                {
                    House       = house,
                    HousePics   = housePics,
                    Attachments = attachments
                };


                MemcachedMgr.Instance.SetValue(cacheKey, houseIndexView, TimeSpan.FromMinutes(1));//还可以指定第四个
            }


            #endregion

            return(View(houseIndexView));
        }