예제 #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 Index()
        {
            if (SessionHelper.CurrentEntity.Is(EntityTypeEnum.Citizen) == false)
            {
                return(RedirectBackWithError("Only citizens can have houses!"));
            }

            var houses = houseRepository.GetOwnedHouses(SessionHelper.CurrentEntity.EntityID);

            var vm = new HouseIndexViewModel(houses);

            return(View(vm));
        }
예제 #3
0
        private void CreateStaticPage(long houseId)
        {
            var house                 = houseService.GetById(houseId);
            var pics                  = houseService.GetPics(houseId);
            var attachments           = attService.GetAttachments(houseId);
            HouseIndexViewModel model = new HouseIndexViewModel();

            model.House       = house;
            model.Pics        = pics;
            model.Attachments = attachments;
            string html = MVCHelper.RenderViewToString(this.ControllerContext, @"~/Views/House/StaticIndex.cshtml", model);

            System.IO.File.WriteAllText("d:/1.txt", html);
        }
예제 #4
0
        private void CreateStaticPage(long houseId)
        {
            var house       = houseService.GetById(houseId);
            var pics        = houseService.GetPics(houseId);
            var attachments = attService.GetAttachments(houseId);

            HouseIndexViewModel model = new HouseIndexViewModel();

            model.House       = house;
            model.Pics        = pics;
            model.Attachments = attachments;
            string html = MVCHelper.RenderViewToString(this.ControllerContext, @"~/Views/House/StaticIndex.cshtml",
                                                       model);

            System.IO.File.WriteAllText(@"E:\Program\NET高级培训\NET掌上租\项目代码\HLX.ZSZ\HLX.ZSZ.FrontWebs\" + houseId + ".html", html);
        }
예제 #5
0
        private void CreateStaticPage(long houseId)
        {
            var house = houseService.GetById(houseId);

            //获得图片信息
            var pics = houseService.GetPics(houseId);
            List <AttachementDTO> atts = new List <AttachementDTO>();
            var attachments            = attService.GetAttachments(houseId);
            HouseIndexViewModel model  = new HouseIndexViewModel();

            model.House       = house;
            model.Pics        = pics;
            model.Attachments = attachments;
            string html = MVCHelper.RenderViewToString(this.ControllerContext, @"~/Views/House/StaticIndex.cshtml", model);

            //静态页面保存到网站的根目录下去,用房子Id命名
            System.IO.File.WriteAllText(@"E:\DemoMVC\ZSZ\ZSZ.FrontWeb\" + houseId + ".html", html);
        }
예제 #6
0
        /// <summary>
        /// 创建前台房子详情的页面静态化
        /// </summary>
        /// <param name="houseId">房子的id</param>
        private void CreateStaticPage(long houseId)
        {
            var house       = houseService.GetById(houseId);
            var pics        = houseService.GetPics(houseId);
            var attachments = attService.GetAttachments(houseId);
            //由于静态化的类是前台的类,重新拷贝一个类到后台
            HouseIndexViewModel model = new HouseIndexViewModel();

            model.House       = house;
            model.Pics        = pics;
            model.Attachments = attachments;
            //由于静态化的是前台的房屋详情页面,不能跨程序集,在本项目中创建一个和前台房屋详情一样的cshtml
            string html = MVCHelper.RenderViewToString(this.ControllerContext, @"~/Views/House/StaticIndex.cshtml",
                                                       model);

            //保存到前台文件夹中
            System.IO.File.WriteAllText(@"D:\UserData\My Documents\Visual Studio 2015\Projects\ZSZ\ZSZ.FrontWeb\" + houseId + ".html", html);
        }
예제 #7
0
        // GET: House
        public ActionResult Index(long id)
        {
            // var house = houseService.GetById(id);
            //if (house==null)
            //{
            //    return View("error",(object)"不存在房源信息");

            //}
            //var pics = houseService.GetPics(id);
            //var attachments = attService.GetAttachments(id);
            //HouseIndexViewModel model = new HouseIndexViewModel();
            //model.House = house;
            //model.Pics = pics;
            //model.Attachments = attachments;
            //return View(model);
            string cacheKey = "HouseIndex_" + id;
            //先尝试去缓存中找

            HouseIndexViewModel model = (HouseIndexViewModel)HttpContext.Cache[cacheKey];

            if (model == null)//缓存中没有找到
            {
                var house = houseService.GetById(id);
                if (house == null)
                {
                    return(View("Error", (object)"不存在的房源id"));
                }
                var pics        = houseService.GetPics(id);
                var attachments = attService.GetAttachments(id);

                model             = new HouseIndexViewModel();
                model.House       = house;
                model.Pics        = pics;
                model.Attachments = attachments;
                //存入缓存
                HttpContext.Cache.Insert("key", model, null, DateTime.Now.AddSeconds(40), System.Web.Caching.Cache.NoSlidingExpiration);
            }
            return(View(model));
        }
예제 #8
0
        public ActionResult Index(long id)
        {
            /*  var house = houseService.GetById(id);
             * if (house==null)
             * {
             *    return View("Error",(object)"不存在的房源Id");
             * }
             * var pics= houseService.GetPics(id);
             * var attachments = attachmentService.GetAttachments(id);
             * string cacheKey = "HouseIndex_" + id;
             *
             *      HouseIndexViewModel model = new HouseIndexViewModel();
             *      model.House = house;
             *      model.Pics = pics;
             *      model.Attachments = attachments;
             */
            string cacheKey = "HouseIndex_" + id;
            //使用asp.net缓存
            HouseIndexViewModel model = (HouseIndexViewModel)HttpContext.Cache[cacheKey];//cacheKey不能重复

            if (model == null)
            {
                var house = houseService.GetById(id);
                if (house == null)
                {
                    return(View("Error", (object)"不存在的房源Id"));
                }
                var pics        = houseService.GetPics(id);
                var attachments = attachmentService.GetAttachments(id);
                model             = new HouseIndexViewModel();
                model.House       = house;
                model.Pics        = pics;
                model.Attachments = attachments;
                HttpContext.Cache.Insert(cacheKey, model, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
            }
            return(View(model));
        }
예제 #9
0
        // GET: House
        public ActionResult Index(long id)
        {
            //var house = houseService.GetById(id);
            //if (house == null)
            //{
            //    return View("Error", (object)"不存在的房源id");
            //}
            //var pics = houseService.GetPics(id);
            //var attachments = attService.GetAttachments(id);

            /*
             * HouseIndexViewModel model = new HouseIndexViewModel();
             * model.House = house;
             * model.Pics = pics;
             * model.Attachments = attachments;*/
            /*
             * string cacheKey = "HouseIndex_" + id;
             * //先尝试去缓存中找
             * HouseIndexViewModel model = (HouseIndexViewModel)HttpContext.Cache[cacheKey];
             * if (model == null)//缓存中没有找到
             * {
             *  var house = houseService.GetById(id);
             *  if (house == null)
             *  {
             *      return View("Error", (object)"不存在的房源id");
             *  }
             *  var pics = houseService.GetPics(id);
             *  var attachments = attService.GetAttachments(id);
             *
             *  model = new HouseIndexViewModel();
             *  model.House = house;
             *  model.Pics = pics;
             *  model.Attachments = attachments;
             *  //存入缓存
             *  HttpContext.Cache.Insert(cacheKey, model, null,
             *      DateTime.Now.AddMinutes(1), TimeSpan.Zero);
             * }
             *  return View(model);*/
            string cacheKey = "HouseIndex_" + id;
            //先尝试去缓存中找
            HouseIndexViewModel model =
                MemcacheMgr.Instance.GetValue <HouseIndexViewModel>(cacheKey);

            if (model == null)//缓存中没有找到
            {
                var house = houseService.GetById(id);
                if (house == null)
                {
                    return(View("Error", (object)"不存在的房源id"));
                }
                var pics        = houseService.GetPics(id);
                var attachments = attService.GetAttachments(id);

                model             = new HouseIndexViewModel();
                model.House       = house;
                model.Pics        = pics;
                model.Attachments = attachments;
                //存入缓存
                MemcacheMgr.Instance.SetValue(cacheKey, model
                                              , TimeSpan.FromMinutes(1));
            }
            return(View(model));
        }
예제 #10
0
        public ActionResult Index(long id)
        {
            #region 没有使用缓存

            /*
             * var house = houseService.GetById(id);
             * if (house == null)
             * {
             *  return View("Error", (object)"不存在的房源id");
             * }
             * //获得图片信息
             * var pics = houseService.GetPics(id);
             * List<AttachementDTO> atts = new List<AttachementDTO>();
             * var attachments = attService.GetAttachments(id);
             *
             * HouseIndexViewModel model = new HouseIndexViewModel();
             * model.House = house;
             * model.Pics = pics;
             * model.Attachments = attachments;
             */
            #endregion


            //内置缓存
            //先看缓存中有没有数据
            //缓存的key的名字一定不能重复
            string cachekey           = "HouseIndex_" + id;
            HouseIndexViewModel model = (HouseIndexViewModel)HttpContext.Cache[cachekey];
            if (model == null)
            {
                //缓存中没有数据再去数据库中查
                var house = houseService.GetById(id);
                if (house == null)
                {
                    return(View("Error", (object)"不存在的房源id"));
                }
                //获得图片信息
                var pics = houseService.GetPics(id);
                List <AttachementDTO> atts = new List <AttachementDTO>();
                var attachments            = attService.GetAttachments(id);
                model             = new HouseIndexViewModel();
                model.House       = house;
                model.Pics        = pics;
                model.Attachments = attachments;
                //查到数据放入缓存
                //HttpContext.Cache.Add(cachekey,model,null,DateTime.Now.AddMinutes(1),TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default,null);
                HttpContext.Cache.Insert(cachekey, model, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
            }


            //可以使用Memcached或者redis优化缓存
            #region Memcached缓存优化,类需要标记为Serializable且要开启memcached服务器,暂不使用

            /*
             * //Memcached缓存优化
             * string cachekey = "HouseIndex_" + id;
             * HouseIndexViewModel model
             *  = (HouseIndexViewModel)MemcachedMg.Instance.GetValue(cachekey);
             *
             * //HouseIndexViewModel model
             * //    = MemcachedMg.Instance.GetValue<HouseIndexViewModel>(cachekey);
             *
             * if (model == null)
             * {
             *  //缓存中没有数据再去数据库中查
             *  var house = houseService.GetById(id);
             *  if (house == null)
             *  {
             *      return View("Error", (object)"不存在的房源id");
             *  }
             *  //获得图片信息
             *  var pics = houseService.GetPics(id);
             *  List<AttachementDTO> atts = new List<AttachementDTO>();
             *  var attachments = attService.GetAttachments(id);
             *  model = new HouseIndexViewModel();
             *  model.House = house;
             *  model.Pics = pics;
             *  model.Attachments = attachments;
             *  //查到数据放入缓存
             *  //HttpContext.Cache.Add(cachekey,model,null,DateTime.Now.AddMinutes(1),TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default,null);
             *  //HttpContext.Cache.Insert(cachekey, model, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
             *  MemcachedMg.Instance.SetValue(cachekey, model,
             *      TimeSpan.FromMinutes(1));
             *  //要求类要是可序列化的,把HouseIndexViewModel标记为Serializable
             *
             * }
             */
            #endregion


            return(View(model));
        }
예제 #11
0
        // GET: House
        public ActionResult Index(long id)
        {
            /*
             * var house = houseService.GetById(id);
             * if (house == null)
             * {
             *  return View("Error", (object)"不存在的房源ID");
             * }
             * var pics = houseService.GetPics(id);
             * var attachments = attachmentService.GetAttachments(id);
             * var model = new HouseIndexViewModel
             * {
             *  House = house,
             *  Pics = pics,
             *  Attachments = attachments,
             * };
             */

            //缓存优化(使用HttpContext.Cache)
            //string cacheKey = "HouseIndex_" + id;
            //HouseIndexViewModel model = (HouseIndexViewModel)HttpContext.Cache[cacheKey];
            //if (model == null)
            //{
            //    var house = houseService.GetById(id);
            //    if (house == null)
            //    {
            //        return View("Error", (object)"不存在的房源ID");
            //    }
            //    var pics = houseService.GetPics(id);
            //    var attachments = attachmentService.GetAttachments(id);
            //    model = new HouseIndexViewModel
            //    {
            //        House = house,
            //        Pics = pics,
            //        Attachments = attachments,
            //    };
            //    HttpContext.Cache.Insert(cacheKey, model, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
            //}


            //缓存优化,使用Memcached
            string cacheKey           = "HouseIndex_" + id;
            HouseIndexViewModel model = MemcacheMgr.Instance.GetValue <HouseIndexViewModel>(cacheKey);

            if (model == null)
            {
                var house = houseService.GetById(id);
                if (house == null)
                {
                    return(View("Error", (object)"不存在的房源ID"));
                }
                var pics        = houseService.GetPics(id);
                var attachments = attachmentService.GetAttachments(id);
                model = new HouseIndexViewModel
                {
                    House       = house,
                    Pics        = pics,
                    Attachments = attachments,
                };
                HttpContext.Cache.Insert(cacheKey, model, null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);

                MemcacheMgr.Instance.SetValue(cacheKey, model, TimeSpan.FromSeconds(10));
            }



            return(View(model));
        }
예제 #12
0
        /// <summary>
        /// 根据房子的id返回房子对应的详细信息
        /// </summary>
        /// <param name="id">房子的id</param>
        /// <returns></returns>
        public ActionResult Index(long id)
        {
            //通过房子的id取得房子的信息
            var house = houseService.GetById(id);

            if (house == null)
            {
                return(View("Error", (object)"不存在的房源id"));
            }
            //通过房子的id取得房子的图片
            var pics = houseService.GetPics(id);
            // 通过房子的id取得房子的配套设施
            var attachments = attService.GetAttachments(id);
            //把房子所有的信息赋值给viewmodel
            HouseIndexViewModel model = new HouseIndexViewModel();

            model.House       = house;
            model.Pics        = pics;
            model.Attachments = attachments;

            ////缓存的key(key不能重复, 使用不同的房子不同的房子id)
            //string cacheKey = "HouseIndex_" + id;
            ////先尝试去缓存中找
            //HouseIndexViewModel model = (HouseIndexViewModel)HttpContext.Cache[cacheKey];
            //if (model == null)//缓存中没有找到,则去数据库取数据
            //{
            //    var house = houseService.GetById(id);
            //    if (house == null)
            //    {
            //        return View("Error", (object)"不存在的房源id");
            //    }
            //    var pics = houseService.GetPics(id);
            //    var attachments = attService.GetAttachments(id);

            //    model = new HouseIndexViewModel();
            //    model.House = house;
            //    model.Pics = pics;
            //    model.Attachments = attachments;
            //    //存入缓存(缓存的key,值为model,null,缓存的过期时间)
            //    HttpContext.Cache.Insert(cacheKey, model, null,
            //        DateTime.Now.AddMinutes(1), TimeSpan.Zero);
            //}


            //string cacheKey = "HouseIndex_" + id;
            ////先尝试去缓存中找,Memcach的类都必须是可序列化(包括关联的类)
            //HouseIndexViewModel model =
            //    MemcacheMgr.Instance.GetValue<HouseIndexViewModel>(cacheKey);
            //if (model == null)//缓存中没有找到
            //{
            //    var house = houseService.GetById(id);
            //    if (house == null)
            //    {
            //        return View("Error", (object)"不存在的房源id");
            //    }
            //    var pics = houseService.GetPics(id);
            //    var attachments = attService.GetAttachments(id);

            //    model = new HouseIndexViewModel();
            //    model.House = house;
            //    model.Pics = pics;
            //    model.Attachments = attachments;
            //    //存入缓存
            //    MemcacheMgr.Instance.SetValue(cacheKey, model
            //        , TimeSpan.FromMinutes(1));
            //}
            return(View(model));
        }
예제 #13
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));
        }