Пример #1
0
        public async Task <IActionResult> Index(SearchInfo input, int page = 1)
        {
            try
            {
                if (input == null)
                {
                    input = new SearchInfo();
                }
                CategoryInfoAsync();
                GetInfo getInfo = new GetInfo(_db, _configuration, _cache);
                #region latest posts 10
                var latestPostResult = await getInfo.GetLatestPostInfoAsync(page, 10, input.Title, input.Category);

                var latestPostMaps = _mapper.Map <List <Post>, List <PostDto> >(latestPostResult);
                ViewBag.LatestPosts = new List <PostDto>();
                if (latestPostMaps.Count > 0)
                {
                    ViewBag.LatestPosts = latestPostMaps;
                }
                #endregion
                #region page
                ViewBag.Query = "";
                if (!string.IsNullOrWhiteSpace(HttpContext.Request.QueryString.ToString()))
                {
                    ViewBag.Query = string.Join('&', HttpContext.Request.QueryString.ToString().Substring(0).Split('&').Where(u => !u.Contains("page")));
                }
                ViewBag.PageIndex       = latestPostResult.PageIndex;
                ViewBag.PageTotal       = latestPostResult.PageTotal;
                ViewBag.PageCount       = latestPostResult.PageCount;
                ViewBag.HasPreViousPage = latestPostResult.HasPreViousPage;
                ViewBag.HasNextPage     = latestPostResult.HasNextPage;
                ViewBag.PageUrl         = "/post";
                ViewData["SearchTitle"] = input.Title;
                ViewData["Category"]    = input.Category;
                #endregion
                #region hot posts 5
                var hotPostResult = await getInfo.GetHotPostInfoAsync();

                var hotPostMaps = _mapper.Map <List <Post>, List <PostDto> >(hotPostResult);
                ViewBag.HotPosts = new List <PostDto>();
                if (hotPostMaps.Count > 0)
                {
                    ViewBag.HotPosts = hotPostMaps;
                }
                #endregion
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return(Redirect("/home/error"));
            }
            finally
            {
                ViewData["Post"] = "active";
                _db.Dispose();
            }
            return(View());
        }
Пример #2
0
        public async Task <IActionResult> Index()
        {
            try
            {
                CategoryInfoAsync();
                GetInfo getInfo = new GetInfo(_db, _configuration, _cache);
                #region hot posts 5
                var hotPostResult = await getInfo.GetHotPostInfoAsync();

                var hotPostMaps = _mapper.Map <List <Post>, List <PostDto> >(hotPostResult);
                ViewBag.HotPosts = new List <PostDto>();
                if (hotPostMaps.Count > 0)
                {
                    ViewBag.HotPosts = hotPostMaps;
                }
                #endregion
                #region latest posts 3
                var latestPostResult = await getInfo.GetLatestPostInfoAsync();

                var latestPostMaps = _mapper.Map <List <Post>, List <PostDto> >(latestPostResult);
                ViewBag.LatestPosts = new List <PostDto>();
                if (latestPostMaps.Count > 0)
                {
                    ViewBag.LatestPosts = latestPostMaps;
                }
                #endregion
                #region slider posts 3
                var stochasticPostResult = await getInfo.GetStochasticPostInfoAsync();

                var stochasticPostMaps = _mapper.Map <List <Post>, List <PostDto> >(stochasticPostResult);
                ViewBag.StochasticPosts = new List <PostDto>();
                if (stochasticPostMaps.Count > 0)
                {
                    ViewBag.StochasticPosts = stochasticPostMaps;
                }

                #endregion
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return(Redirect("/Error"));
            }
            finally
            {
                ViewData["Home"] = "active";
                _db.Dispose();
            }
            return(View());
        }