Esempio n. 1
0
        [OutputCache(Duration = CmsConfig.Cache5Min, VaryByParam = "Content;PageIndex")]//, VaryByCustom = "IsMobile"
        public virtual ActionResult Index(string content, int PageIndex = 0)
        {
            var model = new TagItemsPageModel();

            content = content.Replace("_", " ");
            content = content.Replace("+", " ");
            var TagCurrent      = new Tag();
            var LastItemPubDate = DateTime.Now.AddMinutes(15);

            //if (Content.EqualsX("All") || string.IsNullOrEmpty(Content))
            //    return RedirectToAction(MVC.Tag.Actions.ActionNames.All, MVC.Tag.Name);

            try
            {
                TagCurrent = _unitOfWork.Set <Tag>().SingleOrDefault(x => x.Title.Equals(content) || x.EnValue == content);
                //    if (TagCurrent.Value.Trim().Length != Content.Trim().Length && TagCurrent.EnValue.Trim().Length != Content.Trim().Length)
                //        return RedirectToAction(MVC.Key.ActionNames.Index, MVC.Key.Name, new { Content = Content, PageSize = PageSize, LastItemPubDate });
            }
            catch
            {
                var tagCurrents = _unitOfWork.Set <Tag>().Where(x => x.Value.StartsWith(content));
                if (tagCurrents.Any())
                {
                    TagCurrent = tagCurrents.First();
                }
                else
                {
                    return(RedirectToAction(MVC.Key.ActionNames.Index, MVC.Key.Name, new { Content = content, PageSize = PageSize, LastItemPubDate }));
                }
            }
            if (TagCurrent == null)
            {
                return(RedirectToAction(MVC.Key.ActionNames.Index, MVC.Key.Name, new { Content = content, PageSize = PageSize, LastItemPubDate }));
            }


            #region ViewBag
            //ViewBag.EntityCode = "Tag";
            ViewBag.EntityRef = TagCurrent.Id;
            //ViewBag.PageSize = PageSize;
            ViewBag.Toggle             = "1";
            ViewBag.SearchTextDir      = "text-align:right;direction:rtl";
            ViewBag.Title              = "اخبار " + TagCurrent.Title;
            ViewBag.ImageThumbnail     = TagCurrent.ImageThumbnail;
            ViewBag.HasBackgroundImage = TagCurrent.HasBackgroundImage;
            ViewBag.Content            = string.IsNullOrEmpty(TagCurrent.EnValue) ? TagCurrent.Value.Trim() : TagCurrent.EnValue;
            ViewBag.SearchExpersion    = "Tag:" + TagCurrent.Value;
            ViewBag.PageHeader         = "تازه ترین های " + TagCurrent.Title;
            ViewBag.Discription        = "تازه ترین های اخبار روز و مطالب " + TagCurrent.Title;
            ViewBag.KeyWords           = "," + TagCurrent.EnValue + "," + TagCurrent.Value.Replace("|", ",") + ",اخبار روز,تازه ترین خبرها,خبرخوان";
            ViewBag.TagCurrent         = TagCurrent;
            ViewBag.PageIndex          = PageIndex + 1;
            #endregion
            if (string.IsNullOrEmpty(TagCurrent.Value) && string.IsNullOrEmpty(TagCurrent.EnValue))
            {
                return(RedirectToAction(MVC.Tag.Name, MVC.Tag.ActionNames.All, null));
            }

            #region Body

            model.Items       = _feedItemBusiness.FeedItemsByTag(TagCurrent, PageSize, PageIndex);
            model.VisualItems = _feedItemBusiness.FeedItemsByTag(TagCurrent, _appConfigBiz.GetVisualPostCount() + _appConfigBiz.GetVisualPostCount(), PageIndex, true);
            model.Posts       = _postBiz.GetList().Where(p => !p.MetaData.IsDeleted && p.PublishDate < DateTime.Now && p.Tags.Any(tc => tc.Id == TagCurrent.Id || tc.ParentTagId == TagCurrent.Id))
                                .Take(_appConfigBiz.GetVisualPostCount()).ToList();
            #endregion
            #region SitesTags
            //----------------Top Site in this Tag-------
            var cats = TagCurrent.Categories.ToList();
            try
            {
                if (cats.Any())
                {
                    var catsid = cats.Select(x => x.Id).ToList();
                    var feeds  = _feedBusiness.GetList().Where(f => f.Categories.Any(cf => catsid.Contains(cf.Id)));
                    var sites  = feeds.Select(f => f.Site);
                    ViewBag.TopSites = sites.Distinct().Select(s => new SiteOnlyTitle()
                    {
                        SiteTitle = s.SiteTitle, SiteUrl = s.SiteUrl
                    }).Take(20).ToList();
                }
                //ViewBag.TopSites = context.Database.SqlQuery<SiteOnlyTitle>("Sites_Select_TopByTag {0},{1}", TagCurrent.TagId, 15).ToList();
            }
            catch { }

            var relatedTags = cats.SelectMany(c => c.Tags.Select(t => t)).Distinct().Take(25).ToList();
            //relatedTags.Remove(TagCurrent.Id);
            ViewBag.RelatedTags = relatedTags;

            #endregion
            //B_feeditem.IncreaseVisitCount(res as IEnumerable<FeedItem>);
            model.Items = _feedItemBusiness.DescriptClear(model.Items, TagCurrent.Value).ToList();
            //_feedItemBusiness.Add_FeedItemtoCache(content, PageIndex, View(res), 60);

            #region Tabs
            //var webParts = Ioc.RemoteWpBiz.GetByTag(TagCurrent.Id).ToList();
            //if (webParts.Any())
            //    ViewBag.RemoteWebParts = webParts;
            //else
            //    if (TagCurrent.Categories.Any())
            //    ViewBag.RemoteWebParts = Ioc.RemoteWpBiz.GetByCats(TagCurrent.Categories.Select(c => c.Id).ToList()).ToList();

            //ViewBag.Pages = TagCurrent.Posts.Where(p => p.PostType == PostType.Tab).ToList();

            #endregion
            return(View("Index." + CmsConfig.ThemeName, model));
        }
Esempio n. 2
0
        public virtual ActionResult Index(string content, int PageIndex = 0)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(RedirectToAction(MVC.Tag.All()));
            }
            var Content         = content.Trim();
            var LastItemPubDate = DateTime.Now.AddMinutes(15);

            #region IfSite
            if (Utility.HasFaWord(Content) == false)
            {
                Content = Content.ReplaceX("www.", "");
                if (Content.CountStringOccurrences(".") == 1 || Content.CountStringOccurrences(".") == 2)
                {
                    if (Utility.UrlIsValid(Content) || Utility.UrlIsValid("www." + Content))
                    {
                        return(Redirect("/site/" + Content));
                        //return RedirectToAction(MVC.Site.ActionNames.Index, MVC.Site.Name, new { Content = Content[Content.Count() - 1] == '/' ? Content : Content + "/", PageSize = PageSize, LastItemPubDate = LastItemPubDate });
                    }
                }
            }
            #endregion

            #region IfTag
            Tag TagCurrent = null;
            try
            {
                TagCurrent = _tagBusiness.Get(Content.Replace("_", " "));
                if (TagCurrent == null)
                {
                    var tagCandidate = _tagBusiness.GetList().Where(x => x.Value.Contains(content + "|") || x.Value.Contains("|" + content)).ToList();
                    if (tagCandidate.Any())
                    {
                        TagCurrent = tagCandidate.First();
                        return(RedirectToAction(MVC.Tag.Index(TagCurrent.Title)));
                    }
                }
                else
                {
                    return(RedirectToAction(MVC.Tag.Index(TagCurrent.Title)));
                }
            }
            catch
            {
                //TagCurrent = context.Tags.Where(x => x.Value.Contains(Content)).First();
            }

            #endregion

            #region IfNotFound

            var res = new List <FeedItem>();

            res = _feedItemBusiness.FeedItemsByKey(Content, PageSize, PageIndex).ToList();

            if (res.Count() < 3)
            {
                return(RedirectToAction(MVC.Search.ActionNames.Index, MVC.Search.Name, new { Content = Content }));
            }
            #endregion

            #region ViewBag
            ViewBag.PageSize        = PageSize;
            ViewBag.Toggle          = "1";
            ViewBag.SearchTextDir   = "text-align:right;direction:rtl";
            ViewBag.Title           = Content;
            ViewBag.Content         = Content;
            ViewBag.SearchExpersion = Content;
            ViewBag.PageHeader      = "نتیجه جستجو " + Content;
            ViewBag.RecentTags      = _tagBusiness.RelevantTags(Content).ToList();
            ViewBag.PageIndex       = PageIndex + 1;
            #endregion

            if (string.IsNullOrEmpty(Content))
            {
                return(RedirectToAction(MVC.Tag.Name, MVC.Tag.ActionNames.All, null));
            }

            ViewBag.TopSites = _siteBusiness.GetTopSites(20, 120);
            res = _feedItemBusiness.DescriptClear(res, Content).ToList();

            return(View("Index." + CmsConfig.ThemeName, res));
        }