コード例 #1
0
        // GET: Header
        public ActionResult Index(CardsModels model)
        {
            WorkV3.Common.SitePage curPage = WorkV3.Models.DataAccess.CardsDAO.GetPage(model.No);
            ViewBag.SiteID = curPage.SiteID;
            List <MenusModels> Menus     = Models.DataAccess.MenusDAO.GetFrontMenus(curPage.SiteID);
            SitesModels        SitesInfo = SitesDAO.GetInfo(curPage.SiteID);

            WorkV3.Areas.Backend.Models.DataAccess.KeywordDAO keywordDao = new Areas.Backend.Models.DataAccess.KeywordDAO();    // neil 20180331 新增關鍵字搜尋
            ViewBag.SitesInfo = SitesInfo;

            #region WebLang
            List <SiteLangMenuModel> SiteLang = new List <SiteLangMenuModel>();
            if (uCheck.IsNumeric(curPage.SiteID))
            {
                if (SitesInfo.IsLang)//有開放再抓語言別資料
                {
                    SiteLang = SiteLangMenuDAO.GetDatas(curPage.SiteID);
                }
            }
            ViewBag.SiteLang = SiteLang;
            #endregion

            #region Socal
            List <SitesModels.socialSettingCont> social = new List <SitesModels.socialSettingCont>();
            if (SitesInfo != null)
            {
                if (!string.IsNullOrEmpty(SitesInfo.socialSetting))
                {
                    social = JsonConvert.DeserializeObject <List <SitesModels.socialSettingCont> >(SitesInfo.socialSetting);
                }
            }
            ViewBag.social = social;
            #endregion
            #region  會員功能機制

            Areas.Backend.Models.MemberShipRegSetModels MemberSetModel = Areas.Backend.Models.DataAccess.MemberShipRegSetDAO.GetItem(model.SiteID);
            bool IsEnabledMember = false;
            if (MemberSetModel != null)
            {
                IsEnabledMember = MemberSetModel.IsOpenReg;
            }
            ViewBag.IsEnabledMember = IsEnabledMember;
            #endregion

            ViewBag.SearchPage  = SearchResultDAO.GetSearchPage(curPage.SiteID);
            ViewBag.VPath       = WorkV3.Golbal.UpdFileInfo.GetVPathBySiteID(curPage.SiteID, "Header");
            ViewBag.VMemberPath = WorkV3.Golbal.UpdFileInfo.GetVPathBySiteID(curPage.SiteID, "Member");
            ViewBag.Keywords    = keywordDao.GetAllKeywords(true);
            ViewBag.VMenuPath   = Golbal.UpdFileInfo.GetVPathBySiteID(curPage.SiteID, "Menus");
            int style = model.StylesID;
            return(View("Style" + style, Menus));
        }
コード例 #2
0
        public ActionResult Index(CardsModels model, string key, string SearchType, long?SearchPoster, long?SearchSeries)
        {
            ViewBag.Card = model;
            ViewBag.Key  = key;

            // neil 20180331 新增關鍵字搜尋 start
            bool isPreview = Request["isPreview"] != null && Request["isPreview"] == "true";

            if (!isPreview)
            {
                WorkV3.Areas.Backend.Models.DataAccess.KeywordDAO keywordDao = new Areas.Backend.Models.DataAccess.KeywordDAO();
                keywordDao.AddKeywordQueried(key);
            }
            // neil 20180331 新增關鍵字搜尋 end

            IEnumerable <SearchMenuModel>   menus = SearchResultDAO.GetSearchMenus(model.SiteID);
            IEnumerable <SearchResultModel> items = null;

            // charlie_shan 20180802 新增作者搜尋-> 只搜文章模組 start
            if (!string.IsNullOrEmpty(SearchType))
            {
                if (SearchType == "Poster")
                {
                    if (SearchPoster.HasValue)
                    {
                        ViewBag.PosterModel = ArticlePosterDAO.GetItem(SearchPoster.Value);
                    }
                    items = SearchResultDAO.GetItemsByPoster(menus, key, SearchPoster);
                }
                // charlie_shan 20180822 新增系列搜尋-> 只搜文章模組 start
                else if (SearchType == "Series")
                {
                    items = SearchResultDAO.GetItemsBySeries(menus, key, SearchSeries);
                }
                // charlie_shan 20180822 新增系列搜尋-> 只搜文章模組 end
                else
                {
                    items = SearchResultDAO.GetItems(menus, key);
                }
            }
            else
            {
                items = SearchResultDAO.GetItems(menus, key);
            }
            // charlie_shan 20180802 新增作者搜尋-> 只搜文章模組 end

            ViewBag.SitePages = Models.DataAccess.CardsDAO.GetPages(items.Select(item => item.CardNo)) ?? new Dictionary <long, Common.SitePage>();

            IEnumerable <long> menuIds = items.Select(item => item.MenuID).Distinct();

            menus         = menus.Where(m => menuIds.Contains(m.ID));
            ViewBag.Menus = menus;

            List <SearchMenuModel> singlePageMenus = menus.Where(m => m.Module.ToLower() == "articleintro").ToList();
            List <string[]>        singleRootMenus = SearchResultDAO.GetRootMenus(singlePageMenus.Where(m => m.ParentID > 0).Select(m => m.ParentID));
            Dictionary <string, List <SearchResultModel> > singlePageResults = new Dictionary <string, List <SearchResultModel> >();

            foreach (SearchResultModel item in items)
            {
                SearchMenuModel menu = singlePageMenus.FirstOrDefault(s => s.ID == item.MenuID);
                if (menu == null)
                {
                    continue;
                }

                item.Title = menu.Title;

                string[] rootMenuInfo = singleRootMenus == null ? null : singleRootMenus.FirstOrDefault(r => r[0] == menu.ParentID.ToString());

                List <SearchResultModel> results;
                if (rootMenuInfo == null)
                {
                    if (!singlePageResults.TryGetValue(menu.Title, out results))
                    {
                        results = new List <SearchResultModel>();
                        singlePageResults.Add(menu.Title, results);
                    }
                    results.Add(item);
                    continue;
                }

                string rootMenuName = rootMenuInfo[2];
                if (string.IsNullOrWhiteSpace(rootMenuName))
                {
                    rootMenuName = rootMenuInfo[1];
                }
                else
                {
                    item.Title = rootMenuInfo[1] + " / " + item.Title;
                }

                if (!singlePageResults.TryGetValue(rootMenuName, out results))
                {
                    results = new List <SearchResultModel>();
                    singlePageResults.Add(rootMenuName, results);
                }
                results.Add(item);
            }
            ViewBag.SinglePageResults = singlePageResults;

            SearchResultDAO.GetMenuItems(model.SiteID, key);
            if (!string.IsNullOrEmpty(SearchType))
            {
                if (SearchType == "Poster")
                {
                    ViewBag.MenuResults = new List <SearchMenuResultModel>();
                }
                else
                {
                    ViewBag.MenuResults = SearchResultDAO.GetMenuItems(model.SiteID, key);
                }
            }
            else
            {
                ViewBag.MenuResults = SearchResultDAO.GetMenuItems(model.SiteID, key);
            }

            return(View("Style" + model.StylesID, items));
        }