Пример #1
0
        public ActionResult NewsDetail(string seoUrl)
        {
            int languageId = _workContext.WorkingLanguage.Id;

            dynamic viewBag = base.ViewBag;

            IStaticContentService staticContentService      = this._staticContentService;
            Expression <Func <StaticContent, bool> > status = (StaticContent x) => x.Status == 1;

            viewBag.fixItems = staticContentService.GetTop <int>(3, status, (StaticContent x) => x.ViewCount);

            List <BreadCrumb> breadCrumbs = new List <BreadCrumb>();
            News news = this._newsService.Get((News x) => x.SeoUrl.Equals(seoUrl), true);

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

            News newsLocalized = new News();

            if (news != null)
            {
                newsLocalized = new News
                {
                    Id                = news.Id,
                    MenuId            = news.MenuId,
                    VirtualCategoryId = news.VirtualCategoryId,
                    Language          = news.Language,
                    Status            = news.Status,
                    SeoUrl            = news.SeoUrl,
                    ImageBigSize      = news.ImageBigSize,
                    ImageMediumSize   = news.ImageMediumSize,
                    ImageSmallSize    = news.ImageSmallSize,
                    MenuLink          = news.MenuLink,
                    CreatedDate       = news.CreatedDate,

                    Title           = news.GetLocalizedByLocaleKey(news.Title, news.Id, languageId, "News", "Title"),
                    ShortDesc       = news.GetLocalizedByLocaleKey(news.ShortDesc, news.Id, languageId, "News", "ShortDesc"),
                    Description     = news.GetLocalizedByLocaleKey(news.Description, news.Id, languageId, "News", "Description"),
                    MetaTitle       = news.GetLocalizedByLocaleKey(news.MetaTitle, news.Id, languageId, "News", "MetaTitle"),
                    MetaKeywords    = news.GetLocalizedByLocaleKey(news.MetaKeywords, news.Id, languageId, "News", "MetaKeywords"),
                    MetaDescription = news.GetLocalizedByLocaleKey(news.MetaDescription, news.Id, languageId, "News", "MetaDescription")
                };

                ((dynamic)base.ViewBag).Title       = newsLocalized.MetaTitle;
                ((dynamic)base.ViewBag).KeyWords    = newsLocalized.MetaKeywords;
                ((dynamic)base.ViewBag).SiteUrl     = base.Url.Action("NewsDetail", "News", new { seoUrl = seoUrl, area = "" });
                ((dynamic)base.ViewBag).Description = newsLocalized.MetaDescription;
                ((dynamic)base.ViewBag).Image       = base.Url.Content(string.Concat("~/", newsLocalized.ImageMediumSize));
                ((dynamic)base.ViewBag).MenuId      = newsLocalized.MenuId;
                string[] strArrays = newsLocalized.VirtualCategoryId.Split(new char[] { '/' });
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string   str      = strArrays[i];
                    MenuLink menuLink = this._menuLinkService.Get((MenuLink x) => x.CurrentVirtualId.Equals(str), false);
                    breadCrumbs.Add(new BreadCrumb()
                    {
                        Title   = menuLink.GetLocalizedByLocaleKey(menuLink.MenuName, menuLink.Id, languageId, "MenuLink", "MenuName"),
                        Current = false,
                        Url     = base.Url.Action("GetContent", "Menu", new { area = "", menu = menuLink.SeoUrl })
                    });
                }
                breadCrumbs.Add(new BreadCrumb()
                {
                    Current = true,
                    Title   = newsLocalized.Title
                });
                ((dynamic)base.ViewBag).BreadCrumb = breadCrumbs;
            }
            ((dynamic)base.ViewBag).SeoUrl = newsLocalized.MenuLink.SeoUrl;

            return(base.View(newsLocalized));
        }
Пример #2
0
        public ActionResult GetNewsByCategory(string virtualCategoryId, int?menuId, string title, int page, int?month, int?year)
        {
            var viewBag = ViewBag;

            var sortBuilder = new SortBuilder
            {
                ColumnName  = "CreatedDate",
                ColumnOrder = SortBuilder.SortOrder.Descending
            };
            var paging = new Paging
            {
                PageNumber  = page,
                PageSize    = PageSize,
                TotalRecord = 0
            };

            var news = _newsService.FindAndSort(x => !x.Video && x.Status == (int)Status.Enable && x.VirtualCategoryId.Contains(virtualCategoryId)
                                                , sortBuilder, paging);

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

            Expression <Func <StaticContent, bool> > status = x => x.Status == (int)Status.Enable;

            viewBag.fixItems = _staticContentService.GetTop(3, status, x => x.ViewCount);

            if (month != null)
            {
                news = news.Where(n => n.CreatedDate.Month == month);
            }

            if (year != null)
            {
                news = news.Where(n => n.CreatedDate.Year == year);
            }

            //Get menu category filter
            var menuCategoryFilter = _menuLinkService.GetByOption(virtualId: virtualCategoryId);

            var newsLocalized = news
                                .Select(x => x.ToModel());

            if (news.IsAny())
            {
                var pageInfo = new Helper.PageInfo(ExtentionUtils.PageSize, page, paging.TotalRecord, i => Url.Action("GetContent", "Menu", new { page = i }));
                ViewBag.PageInfo  = pageInfo;
                ViewBag.CountItem = pageInfo.TotalItems;

                var breadCrumbs = new List <BreadCrumb>();

                //Lấy bannerId từ post để hiển thị banner trên post
                ViewBag.BannerId = menuCategoryFilter.FirstOrDefault(x => x.VirtualId == virtualCategoryId).Id;

                var categories = virtualCategoryId.Split('/');
                for (var i = 0; i < categories.Length; i++)
                {
                    var str      = categories[i];
                    var menuLink = _menuLinkService.GetByMenuName(str, title);
                    if (menuLink != null)
                    {
                        //Lấy bannerId từ post để hiển thị banner trên post
                        if (i == 0)
                        {
                            ViewBag.BannerId = menuLink.Id;
                        }
                        breadCrumbs.Add(new BreadCrumb
                        {
                            Title   = menuLink.GetLocalized(m => m.MenuName, menuLink.Id),
                            Current = false,
                            Url     = Url.Action("GetContent", "Menu", new { area = "", menu = menuLink.SeoUrl })
                        });
                    }
                }
                breadCrumbs.Add(new BreadCrumb
                {
                    Current = true,
                    Title   = title
                });
                ViewBag.BreadCrumb = breadCrumbs;
            }

            ViewBag.MenuId    = menuId;
            ViewBag.VirtualId = virtualCategoryId;
            ViewBag.Title     = title;

            return(PartialView(newsLocalized));
        }
Пример #3
0
        public ActionResult GetNewsByCategory(string virtualCategoryId, int?menuId, string title, int page)
        {
            int languageId = _workContext.WorkingLanguage.Id;

            ((dynamic)base.ViewBag).MenuId    = menuId;
            ((dynamic)base.ViewBag).VirtualId = virtualCategoryId;
            dynamic viewBag = base.ViewBag;

            IStaticContentService staticContentService      = this._staticContentService;
            Expression <Func <StaticContent, bool> > status = (StaticContent x) => x.Status == 1;

            viewBag.fixItems = staticContentService.GetTop <int>(3, status, (StaticContent x) => x.ViewCount);

            SortBuilder sortBuilder = new SortBuilder()
            {
                ColumnName  = "CreatedDate",
                ColumnOrder = SortBuilder.SortOrder.Descending
            };
            Paging paging = new Paging()
            {
                PageNumber  = page,
                PageSize    = base._pageSize,
                TotalRecord = 0
            };

            IEnumerable <News> news = this._newsService.FindAndSort((News x) => !x.Video && x.Status == 1 && x.VirtualCategoryId.Contains(virtualCategoryId), sortBuilder, paging);

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

            IEnumerable <News> newsLocalized = news
                                               .Select(x =>
            {
                return(x.ToModel());
            });

            if (news.IsAny())
            {
                Helper.PageInfo pageInfo = new Helper.PageInfo(ExtentionUtils.PageSize, page, paging.TotalRecord, (int i) => base.Url.Action("GetContent", "Menu", new { page = i }));
                ((dynamic)base.ViewBag).PageInfo  = pageInfo;
                ((dynamic)base.ViewBag).CountItem = pageInfo.TotalItems;

                MenuLink          menuLink    = null;
                List <BreadCrumb> breadCrumbs = new List <BreadCrumb>();
                string[]          strArrays2  = virtualCategoryId.Split(new char[] { '/' });
                for (int i1 = 0; i1 < (int)strArrays2.Length; i1++)
                {
                    string str = strArrays2[i1];
                    menuLink = this._menuLinkService.Get((MenuLink x) => x.CurrentVirtualId.Equals(str) && x.Id != menuId, false);

                    if (menuLink != null)
                    {
                        breadCrumbs.Add(new BreadCrumb()
                        {
                            Title   = menuLink.GetLocalizedByLocaleKey(menuLink.MenuName, menuLink.Id, languageId, "MenuLink", "MenuName"),
                            Current = false,
                            Url     = base.Url.Action("GetContent", "Menu", new { area = "", menu = menuLink.SeoUrl })
                        });
                    }
                }
                breadCrumbs.Add(new BreadCrumb()
                {
                    Current = true,
                    Title   = title
                });
                ((dynamic)base.ViewBag).BreadCrumb = breadCrumbs;
            }

            ((dynamic)base.ViewBag).Title = title;

            return(base.PartialView(newsLocalized));
        }