예제 #1
0
        public ActionResult List(string groupTitle = "", int pageIndex = 0)
        {
            groupTitle = groupTitle.DeNormalizeForUrl();

            var group   = Groups.GetByTitle(groupTitle, _groupType);
            int?groupID = null;

            if (group != null)
            {
                groupID = group.ID;
            }

            if (pageIndex > 0)
            {
                pageIndex = pageIndex - 1;
            }
            else
            {
                pageIndex = 0;
            }

            var list           = Articles.GetBlogList(pageIndex, pageSize, OnlineStore.Models.Enums.ArticleType.Blog, DateTime.Now, groupID);
            var latestPosts    = Articles.GetLatestPosts(groupID.HasValue ? groupID.Value : (int?)null);
            var latestComments = ArticleComments.GetLatestComments(ArticleType.Blog, 6);

            var count      = Articles.CountBlogList(OnlineStore.Models.Enums.ArticleType.Blog, DateTime.Now, groupID);
            var totalPages = (int)Math.Ceiling((decimal)count / pageSize);
            var paging     = Utilities.MakePaging(totalPages, pageIndex + 1);

            foreach (var item in list)
            {
                try
                {
                    var user = Identity.OSUsers.GetByID(item.UserID);
                    item.UserTitle = user.Firstname + " " + user.Lastname;
                }
                catch (Exception ex)
                {
                    item.UserTitle = StaticValues.HomeTitle;
                }
            }

            var model = new BlogList
            {
                DataList         = list,
                GroupID          = groupID,
                Paging           = paging,
                TotalPages       = totalPages,
                CurrentPageIndex = pageIndex,
                LatestPosts      = latestPosts,
                LatestComments   = latestComments
            };

            return(View(url + "Index.cshtml", model: model));
        }
예제 #2
0
        public ActionResult Details(int id)
        {
            #region Details

            var blogDetails = Articles.GetBlogByID(id);

            if (blogDetails == null)
            {
                return(HttpNotFound());
            }

            try
            {
                var user = Identity.OSUsers.GetByID(blogDetails.UserID);
                blogDetails.UserTitle = user.Firstname + " " + user.Lastname;
            }
            catch (Exception)
            {
                blogDetails.UserTitle = StaticValues.HomeTitle;
            }

            blogDetails.Text = HttpUtility.HtmlDecode(blogDetails.Text);

            #endregion Details

            var latestPosts    = Articles.GetLatestPosts(blogDetails.GroupID);
            var latestComments = ArticleComments.GetLatestComments(ArticleType.Blog, 6, blogDetails.GroupID);
            var comments       = ArticleComments.GetByArticleID(id);
            var relatedPosts   = RelatedArticles.GetRelatedArticles(id);
            var group          = Groups.GetByID(blogDetails.GroupID);

            #region Products

            var products = Products.GetRandom();
            Products.FillProductItems(UserID, products, StaticValues.RelatedProductImageSize);

            var shopProducts = new RelatedProductSettings
            {
                Products = products,
                Title    = "فروشگاه آنلاین استور"
            };

            #endregion Products

            // increase Visits
            increaseVisits(id);

            BlogDetail model = new BlogDetail
            {
                BlogDetails    = blogDetails,
                LatestComments = latestComments,
                LatestPosts    = latestPosts,
                Comments       = comments,
                RelatedPosts   = relatedPosts,
                Products       = shopProducts
            };

            ViewBag.Title       = blogDetails.Title;
            ViewBag.Description = blogDetails.Summary;
            ViewBag.Keywords    = group.Title + ", " + group.TitleEn +
                                  ", " + blogDetails.Title.Split(' ').Aggregate((a, b) => b + ", " + a);
            ViewBag.OGType  = "article";
            ViewBag.OGImage = StaticValues.WebsiteUrl + StaticPaths.ArticleImages + blogDetails.Image;

            return(View(url + "Details.cshtml", model: model));
        }