コード例 #1
0
        private static string GetWhereSql(ArticleSettingModels setting, string key, string type, long?typeId = null)
        {
            List <string> where = new List <string>();
            where.Add("IsIssue = 1");
            where.Add("MenuID = " + setting.MenuID);

            if (!string.IsNullOrWhiteSpace(key))
            {
                key = $"N'%{ key.Replace("'", "''") }%'";
                List <string> orSql = new List <string>();
                orSql.Add($"Title Like { key }");
                orSql.Add($"ID IN (Select SourceNo From Paragraph Where (Title Like { key } OR Contents Like { key }))");
                orSql.Add($"ID IN (Select SourceNo From Paragraph Where ID IN (Select SourceNo From ResourceImages Where (Spec Like { key } OR SpecDetail Like { key })))");
                orSql.Add($"ID IN (Select SourceNo From SEO Where (Keywords Like { key }) AND MenuID = { setting.MenuID })");
                where.Add($"({ string.Join(" OR ", orSql) })");
            }

            if (!string.IsNullOrWhiteSpace(type) && type != "全部")
            {
                where.Add($"ID IN (Select ArticleID From ArticleToType Where TypeID IN (Select ID From ArticleTypes Where IsIssue = 1 And ID IN ({ type.Replace("'", "''") }) And MenuID = { setting.MenuID }))");
            }

            if (typeId != null)
            {
                where.Add($"ID IN (Select ArticleID From ArticleToType Where TypeID = { typeId })");
            }
            else
            {
                if (setting.Types != "all")
                {
                    IEnumerable <long> types = setting.GetTypes();
                    if (types?.Count() > 0)
                    {
                        where.Add($"ID IN (Select ArticleID From ArticleToType Where TypeID In ({ string.Join(", ", types) }))");
                    }
                    else
                    {
                        where.Add("1 <> 1"); // 不選取任何資料
                    }
                }
            }

            IEnumerable <int> issueSetting = setting.GetIssueSetting();

            if (issueSetting.Count() == 1)
            {
                if (issueSetting.Contains(0))
                {
                    where.Add("(IssueStart IS NULL OR IssueStart <= GETDATE()) AND (IssueEnd IS NULL OR IssueEnd >= GETDATE())");
                }
                else
                {
                    where.Add("IssueEnd <= GETDATE()");
                }
            }

            return(string.Join(" AND ", where));
        }
コード例 #2
0
ファイル: ArticleController.cs プロジェクト: jim-deng-git/Ask
        public ActionResult Index(CardsModels model, string key, string type, long?typeId, int?index)
        {
            ViewBag.SiteID = model.SiteID;

            long menuId = CardsDAO.GetMenuID(model.No);

            ViewBag.Menu = MenusDAO.GetInfo(model.SiteID, menuId);

            ViewBag.SitePage = CardsDAO.GetPage((long)MenusDAO.GetFirstCardNo(menuId, "Article"));
            SitePage page = CardsDAO.GetPage(model.No);

            ArticleSettingModels setting = ArticleSettingDAO.GetItem(menuId);

            #region 文章列表是否限制會員觀看
            if (setting.ReadMode == 1 && !string.IsNullOrWhiteSpace(setting.ReadModeSet))
            {
                Member curUser      = Member.Current;
                string IdentityName = ""; //限制身分的名稱
                IEnumerable <Areas.Backend.Models.CategoryModels> listReadModeCategorie = Areas.Backend.Models.DataAccess.CategoryDAO.GetItems(IdentityType, setting.ReadModeSet);
                foreach (var readModeList in listReadModeCategorie)
                {
                    IdentityName += readModeList.Title + "、";
                }
                IdentityName         = IdentityName.TrimEnd('、');
                ViewBag.IdentityName = IdentityName;

                if (curUser == null)
                {
                    ViewBag.CheckReadMode = false;
                    ViewBag.IsLogin       = false;
                }
                else
                {
                    bool checkReadMode = ArticleDAO.ListCheckReadMode(curUser.ID, IdentityType, listReadModeCategorie);
                    if (!checkReadMode)
                    {
                        ViewBag.CheckReadMode = false;
                    }
                }
            }
            #endregion

            if (setting.PagingMode == "不分頁")
            {
                setting.PageSize = int.MaxValue;
            }

            IEnumerable <ArticleTypesModels> types = ArticleTypesDAO.GetItems(menuId);
            if (setting.Types != "all")
            {
                IEnumerable <long> allowTypeIds = setting.GetTypes();
                types         = types.Where(t => allowTypeIds.Contains(t.ID));
                setting.Types = string.Join(",", types.Select(t => t.ID));
            }
            ViewBag.Types = types;

            int pageIndex = index ?? 1;

            int totalRecord;
            IEnumerable <ArticleModels> items = ArticleDAO.GetItems(setting, key, type, typeId, pageIndex, out totalRecord);

            ViewBag.ItemTypes = ArticleDAO.GetItemTypes(items.Select(item => item.ID));
            ViewBag.ItemPages = CardsDAO.GetPages(items.Select(item => item.CardNo));

            ViewBag.UploadUrl  = UpdFileInfo.GetVPathByMenuID(model.SiteID, menuId).TrimEnd('/') + "/";
            ViewBag.Pagination = new Pagination {
                PageSize = setting.PageSize, PageIndex = pageIndex, TotalRecord = totalRecord
            };
            ViewBag.Setting = setting;
            ViewBag.Type    = type;

            int style = model.StylesID == 0 ? 1 : model.StylesID;
            // style = 6;
            return(View("ListStyle" + style, items));
        }
コード例 #3
0
ファイル: PagesDAO.cs プロジェクト: jim-deng-git/Ask
        public static ViewModels.SEORelationModel GetContentSEO(long SiteID, long MenuID, long PageNo)
        {
            ViewModels.SEORelationModel seoModel = new ViewModels.SEORelationModel();
            string newUploadUrl = WorkV3.Golbal.UpdFileInfo.GetVPathByMenuID(SiteID, MenuID).TrimEnd('/') + "/";
            //WorkLib.WriteLog.Write(true, MenuID.ToString());
            List <ZonesModels> zoneList = ZonesDAO.GetPageData(SiteID, PageNo);

            if (zoneList != null && zoneList.Count > 0)
            {
                for (int i = 0; i < zoneList.Count; i++)
                {
                    List <CardsModels> cardList = CardsDAO.GetZoneData(SiteID, zoneList[i].No);
                    if (cardList != null && cardList.Count > 0)
                    {
                        switch (cardList[0].CardsType)
                        {
                        case "Article":
                            ArticleModels articleModel = ArticleDAO.GetItemByCard(cardList[0].No);

                            if (articleModel != null)
                            {
                                var authors = ArticleDAO.GetItemPosters(articleModel.ID);
                                if (authors != null && authors.Count() > 0)
                                {
                                    foreach (ArticlePosterModels auhtor in authors)
                                    {
                                        seoModel.Author += auhtor.Name + ";";
                                    }
                                    seoModel.Author = seoModel.Author.Trim(';');
                                }
                                IEnumerable <ArticleTypesModels> types = articleModel.GetTypes();
                                seoModel.Keywords = string.Join(";", types.Select(t => t.Name));

                                if (!string.IsNullOrEmpty(articleModel.Icon))     // 取得[內文/頁面細節/自行設定代表圖]
                                {
                                    ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(articleModel.Icon);
                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                }
                                else
                                {
                                    if (articleModel.CustomIcon)     // 取得[內文 主影片 自行上傳圖片]
                                    {
                                        if (!string.IsNullOrEmpty(articleModel.VideoImg))
                                        {
                                            ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(articleModel.VideoImg);
                                            seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                        }
                                    }
                                    else
                                    {
                                        if (!string.IsNullOrEmpty(articleModel.VideoImg))
                                        {
                                            seoModel.SocialImage = articleModel.VideoImg;     //[ 內文 主影片 影片截圖]
                                        }
                                    }
                                }
                                var paragraphs = ParagraphDAO.GetItems(articleModel.ID);
                                if (paragraphs != null && paragraphs.Count() > 0)
                                {
                                    foreach (ParagraphModels paragraph in paragraphs)
                                    {
                                        //都沒取到圖, 則繼續取段落的圖
                                        if (string.IsNullOrEmpty(seoModel.SocialImage))
                                        {
                                            if (paragraph.MatchType == "img")
                                            {
                                                IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow);
                                                if (images != null && images.Count() > 0)
                                                {
                                                    ResourceImagesModels imgModel = images.FirstOrDefault();
                                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                                }
                                            }
                                        }
                                        if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                                        {
                                            if (string.IsNullOrEmpty(seoModel.Description))
                                            {
                                                seoModel.Description = paragraph.Contents.TrimTags().Truncate(100);
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                        case "ArticleIntro":
                            ArticleIntroModels articleIntroModel = ArticleIntroDAO.GetItem(cardList[0].No);
                            if (articleIntroModel != null)
                            {
                                ArticleSettingModels             setting = ArticleSettingDAO.GetItem(MenuID);
                                IEnumerable <ArticleTypesModels> types   = ArticleTypesDAO.GetItems(MenuID);
                                if (setting.Types != "all")
                                {
                                    IEnumerable <long> allowTypeIds = setting.GetTypes();
                                    types             = types.Where(t => allowTypeIds.Contains(t.ID));
                                    seoModel.Keywords = string.Join(",", types.Select(t => t.Name));
                                }
                                else
                                {
                                    seoModel.Keywords = string.Join(",", types.Select(t => t.Name));
                                }

                                if (!string.IsNullOrEmpty(articleIntroModel.Icon))     // 取得[內文/頁面細節/自行設定代表圖]
                                {
                                    ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(articleIntroModel.Icon);
                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                }
                                var paragraphs = ParagraphDAO.GetItems(articleIntroModel.ID);
                                if (paragraphs != null && paragraphs.Count() > 0)
                                {
                                    foreach (ParagraphModels paragraph in paragraphs)
                                    {
                                        //都沒取到圖, 則繼續取段落的圖
                                        if (string.IsNullOrEmpty(seoModel.SocialImage))
                                        {
                                            if (paragraph.MatchType == "img")
                                            {
                                                IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow);
                                                if (images != null && images.Count() > 0)
                                                {
                                                    ResourceImagesModels imgModel = images.FirstOrDefault();
                                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                                }
                                            }
                                        }
                                        if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                                        {
                                            if (string.IsNullOrEmpty(seoModel.Description))
                                            {
                                                seoModel.Description = paragraph.Contents.TrimTags().Truncate(100);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            return(seoModel);
        }