Example #1
0
        /// <summary>
        /// If no title or category, could be just listing page.
        /// If no title, but category is set, probably a category listing page
        /// If title and category are set, individual blog.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="category"></param>
        /// <param name="date"></param>
        /// <returns>View</returns>
        public ActionResult Index(string title, string category, string date)
        {
            // Blog Listing Homepage
            if (String.IsNullOrEmpty(title) && String.IsNullOrEmpty(category))
            {
                var model = new BlogHomeViewModel(date);
                return(View("~/Views/Home/Blog.cshtml", model));
            }
            // Category

            if (String.IsNullOrEmpty(title))
            {
                // Category
                var cats = Context.BlogCategories.ToList().Select(x => ContentUtils.GetFormattedUrl(x.CategoryName));

                if (cats.Contains(category))
                {
                    var model = new CategorySingleViewModel(category, Server);
                    return(View("~/Views/Blog/CategoriesSingle.cshtml", model));
                }

                // Not a blog category or tags page
                HttpContext.Response.StatusCode = 404;
                return(View("~/Views/Home/Error404.cshtml"));
            }

            // Tag
            if (category == "tags" && !string.IsNullOrEmpty(title))
            {
                var model = new TagSingleViewModel(title);
                return(View("~/Views/Blog/TagSingle.cshtml", model));
            }

            // Blog User
            if (category == "user" && !string.IsNullOrEmpty(title))
            {
                var model = new BlogsByUserViewModel(title);
                return(View("~/Views/Blog/BlogsByUser.cshtml", model));
            }

            // Category is set and we are trying to view an individual blog
            var blog = Context.Blogs.FirstOrDefault(x => x.PermaLink == title);

            if (blog != null)
            {
                var theModel = new BlogSingleHomeViewModel(title);
                return(View("~/Views/Home/BlogSingle.cshtml", theModel));
            }

            // Not a blog category or a blog
            HttpContext.Response.StatusCode = 404;
            return(View("~/Views/Home/Error404.cshtml"));
        }
Example #2
0
        public ActionResult Search(string searchString, int page = 0, string view = Constant.Blog.String.ListView)
        {
            int            skip     = page * Constant.Blog.Integer.PagingDefaultTake;
            List <Article> articles = bService.SearchArticle(skip, searchString);
            ICollection <ArticlePreviewViewModel> articlePreviewVMs =
                articles.Select(Mapper.Map <Article, ArticlePreviewViewModel>)    // Using Mapper with Collection
                .ToList();

            for (int i = 0; i < articlePreviewVMs.Count; i++)
            {
                articlePreviewVMs.ElementAt(i).UserInfo.CreateMainPostDate = articlePreviewVMs.ElementAt(i).PublicDate.Value;
                if (Request.IsAuthenticated)
                {
                    articlePreviewVMs.ElementAt(i).Bookmarked =
                        articlePreviewVMs.ElementAt(i).UserId != User.Identity.GetUserId <int>() &&
                        articles.ElementAt(i).BookmarkUsers
                        .Where(u => u.Id == User.Identity.GetUserId <int>()).Count() > 0;
                }
            }

            if (page == 0)
            {
                BlogHomeViewModel blogHomeVM = new BlogHomeViewModel();
                blogHomeVM.Name = "Có " + bService.CountSearchResult(searchString)
                                  + " Kết Quả Tìm Kiếm Cho \"" + searchString + "\"";
                ViewBag.Tab         = Constant.Blog.String.HomeSearchTab;
                ViewBag.System      = Constant.String.BlogSystem;
                ViewBag.TabParam    = searchString;
                blogHomeVM.Articles = articlePreviewVMs;
                blogHomeVM.View     = view;
                var cookie = new HttpCookie("returnUrl", Request.Url.AbsolutePath + Request.Url.Query);
                cookie.Expires = DateTime.Now.AddMinutes(5);
                Response.Cookies.Add(cookie);
                return(View("Views/BlogHomeView", blogHomeVM));
            }
            else
            {
                if (view == Constant.Blog.String.GridView)
                {
                    return(PartialView("Partials/_ArticleGridPartialView", articlePreviewVMs));
                }
                else
                {
                    return(PartialView("Partials/_ArticleListPartialView", articlePreviewVMs));
                }
            }
        }
Example #3
0
        public BlogHomeViewModel LoadBlogHome(string date = "")
        {
            var homeModel = new BlogHomeViewModel();
            var model     = new BlogListModel(_context);

            homeModel.MaxBlogCount = model.GetBlogSettings().MaxBlogsOnHomepageBeforeLoad;
            homeModel.SkipBlogs    = homeModel.MaxBlogCount;

            homeModel.BlogTitle = model.GetBlogSettings().BlogTitle;

            homeModel.FeaturedBlog = _context.Blogs.FirstOrDefault(x => x.IsFeatured);

            homeModel.CurrentMonth = "";

            homeModel.AllBlogs = _context.Blogs.Where(x => x.IsActive).ToList();

            homeModel.BlogRoll = homeModel.AllBlogs.Where(x => x.IsActive)
                                 .OrderByDescending(x => x.Date)
                                 .Take(homeModel.MaxBlogCount)
                                 .ToList();

            homeModel.BlogCats = new BlogsCategoriesViewModel("");

            if (!String.IsNullOrEmpty(date))
            {
                var startDate = Convert.ToDateTime(date);

                homeModel.CurrentMonth = startDate.ToString("MM/yyyy");

                homeModel.BlogRoll =
                    _context.Blogs.Where(
                        x => x.IsActive &&
                        (x.Date.Month == startDate.Month) &&
                        (x.Date.Year == startDate.Year)
                        )
                    .OrderByDescending(x => x.Date)
                    .Take(homeModel.MaxBlogCount)
                    .ToList();
            }

            return(homeModel);
        }
Example #4
0
        public ActionResult Tag(string tag = "", int page = 0)
        {
            int skip = page * Constant.Blog.Integer.PagingDefaultTake;
            //Tag tagEntity = cService.GetTag(tag);
            List <Article> articles = bService.GetArticles(tag, skip);
            ICollection <ArticlePreviewViewModel> articlePreviewVMs =
                articles.Select(Mapper.Map <Article, ArticlePreviewViewModel>)    // Using Mapper with Collection
                .ToList();

            for (int i = 0; i < articlePreviewVMs.Count; i++)
            {
                articlePreviewVMs.ElementAt(i).UserInfo.CreateMainPostDate = articlePreviewVMs.ElementAt(i).PublicDate.Value;
                if (Request.IsAuthenticated)
                {
                    articlePreviewVMs.ElementAt(i).Bookmarked =
                        articlePreviewVMs.ElementAt(i).UserId != User.Identity.GetUserId <int>() &&
                        articles.ElementAt(i).BookmarkUsers
                        .Where(u => u.Id == User.Identity.GetUserId <int>()).Count() > 0;
                }
            }

            if (page == 0)
            {
                BlogHomeViewModel blogHomeVM = new BlogHomeViewModel();
                blogHomeVM.Name     = "Câu hỏi có thẻ \"" + tag + "\"";
                ViewBag.Tab         = Constant.Blog.String.HomeTagTab;
                ViewBag.System      = Constant.String.BlogSystem;
                ViewBag.TabParam    = tag;
                blogHomeVM.Articles = articlePreviewVMs;
                var cookie = new HttpCookie("returnUrl", Request.Url.AbsolutePath + Request.Url.Query);
                cookie.Expires = DateTime.Now.AddMinutes(5);
                Response.Cookies.Add(cookie);
                return(View("Views/BlogHomeView", blogHomeVM));
            }
            else
            {
                return(PartialView("Partials/_ArticleGridPartialView", articlePreviewVMs));
            }
        }
        public new ActionResult Index(RenderModel model)
        {
            var blogHomeModel = new BlogHomeViewModel(model.Content);

            return(View("BlogHome", blogHomeModel));
        }
Example #6
0
        public override ActionResult Index(RenderModel model)
        {
            var blogHomeModel = new BlogHomeViewModel(model.Content);

            return(CurrentTemplate(blogHomeModel));
        }
        public ActionResult Home(BlogHomeViewModel vm)
        {
            string connStr = ConfigurationManager.ConnectionStrings["hetoshiCharityDBConnectionString"].ConnectionString;

            string oldNew = Request.QueryString["type"];

            currentRow = Convert.ToInt32(Request.QueryString["lastID"]);

            if (oldNew == "older")
            {
                currentRow += 1;
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    using (SqlCommand comm = new SqlCommand("SELECT * FROM (SELECT Id, Date, Blog_Post_Title, Blog_Post_Content, " +
                                                            "ROW_NUMBER() OVER (ORDER BY Id DESC) AS 'Row' FROM BlogPostTable) AS A WHERE Row BETWEEN " + currentRow + " AND " + (currentRow + 2), conn))

                    //    (" SELECT (TOP 3 ROW_NUMBER() OVER(ORDER BY Id DESC) AS Row, " +
                    //"Id, Date, Blog_Post_Title, Blog_Post_Content FROM BlogPostTable " +
                    //"WHERE Row BETWEEN " + currentRow + " AND " + (currentRow + 3), conn))

                    {
                        conn.Open();
                        using (SqlDataReader dr = comm.ExecuteReader())
                        {
                            string blogPostDate    = null;
                            string blogPostTitle   = null;
                            string blogPostContent = null;
                            int    i = 0;

                            while (dr.Read())
                            {
                                blogPostDate             = Convert.ToString(dr["Date"]);
                                blogPostTitle            = Convert.ToString(dr["Blog_Post_Title"]);
                                blogPostContent          = Convert.ToString(dr["Blog_Post_Content"]);
                                currentRow               = Convert.ToInt32(dr["Row"]);
                                TempData["bpd" + i + ""] = blogPostDate;
                                TempData["bpt" + i + ""] = blogPostTitle;
                                TempData["bpc" + i + ""] = blogPostContent;
                                TempData["currentRow"]   = currentRow;
                                //vm.BlogPostDate = blogPostDate;
                                //vm.BlogPostTitle = blogPostTitle;
                                //vm.BlogPostContent = blogPostContent;
                                i++;
                            }
                        }
                        conn.Close();
                    }
                }
            }
            else if (oldNew == "newer")
            {
                currentRow -= 2;
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    using (SqlCommand comm = new SqlCommand("SELECT * FROM (SELECT Id, Date, Blog_Post_Title, Blog_Post_Content, " +
                                                            "ROW_NUMBER() OVER (ORDER BY Id DESC) AS 'Row' FROM BlogPostTable) AS A WHERE Row BETWEEN " + (currentRow) + " AND " + (currentRow + 2), conn))
                    {
                        conn.Open();
                        using (SqlDataReader dr = comm.ExecuteReader())
                        {
                            string blogPostDate    = null;
                            string blogPostTitle   = null;
                            string blogPostContent = null;
                            int    i = 0;

                            while (dr.Read())
                            {
                                blogPostDate             = Convert.ToString(dr["Date"]);
                                blogPostTitle            = Convert.ToString(dr["Blog_Post_Title"]);
                                blogPostContent          = Convert.ToString(dr["Blog_Post_Content"]);
                                currentRow               = Convert.ToInt32(dr["Row"]);
                                TempData["bpd" + i + ""] = blogPostDate;
                                TempData["bpt" + i + ""] = blogPostTitle;
                                TempData["bpc" + i + ""] = blogPostContent;
                                TempData["currentRow"]   = currentRow;
                                //vm.BlogPostDate = blogPostDate;
                                //vm.BlogPostTitle = blogPostTitle;
                                //vm.BlogPostContent = blogPostContent;
                                i++;
                            }
                        }
                        conn.Close();
                    }
                }
            }
            else
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    using (SqlCommand comm = new SqlCommand("SELECT * FROM (SELECT Id, Date, Blog_Post_Title, Blog_Post_Content, " +
                                                            "ROW_NUMBER() OVER (ORDER BY Id DESC) AS 'Row' FROM BlogPostTable) AS A WHERE Row <= 3", conn))

                    //(" SELECT TOP 3 ROW_NUMBER() OVER(ORDER BY Id DESC) AS Row, " +
                    //"Id, Date, Blog_Post_Title, Blog_Post_Content FROM BlogPostTable", conn))
                    {
                        conn.Open();
                        using (SqlDataReader dr = comm.ExecuteReader())
                        {
                            string blogPostDate    = null;
                            string blogPostTitle   = null;
                            string blogPostContent = null;

                            int i = 0;

                            while (dr.Read())
                            {
                                blogPostDate             = Convert.ToString(dr["Date"]);
                                blogPostTitle            = Convert.ToString(dr["Blog_Post_Title"]);
                                blogPostContent          = Convert.ToString(dr["Blog_Post_Content"]);
                                currentRow               = Convert.ToInt32(dr["Row"]);
                                TempData["bpd" + i + ""] = blogPostDate;
                                TempData["bpt" + i + ""] = blogPostTitle;
                                TempData["bpc" + i + ""] = blogPostContent;
                                TempData["currentRow"]   = currentRow;
                                //vm.BlogPostDate = blogPostDate;
                                //vm.BlogPostTitle = blogPostTitle;
                                //vm.BlogPostContent = blogPostContent;
                                i++;
                            }
                        }
                        conn.Close();
                    }
                }
            }
            return(View());
        }