Ejemplo n.º 1
0
        private void RecommendHandler2(long id, ArticleSettingModels setting, string uploadUrl, IEnumerable <ArticleTypesModels> types)
        {
            if (setting.ExtendReadOpen2)
            {
                IEnumerable <ArticleModels> recommends         = ArticleDAO.GetRecommendItems2(setting, id, types.Select(t => t.ID));
                Dictionary <long, SitePage> recommendSitePages = CardsDAO.GetPages(recommends.Select(r => r.CardNo));

                Dictionary <long, dynamic> imgPathInfo = new Dictionary <long, dynamic>();
                imgPathInfo.Add(setting.MenuID, new { Setting = setting, UploadUrl = uploadUrl });

                foreach (ArticleModels item in recommends)
                {
                    SitePage page = recommendSitePages[item.CardNo];

                    dynamic pathInfo;
                    if (!imgPathInfo.TryGetValue(page.MenuID, out pathInfo))
                    {
                        ArticleSettingModels newSetting = ArticleSettingDAO.GetItem(page.MenuID);
                        string newUploadUrl             = UpdFileInfo.GetVPathByMenuID(page.SiteID, page.MenuID).TrimEnd('/') + "/";
                        pathInfo = new { Setting = newSetting, UploadUrl = newUploadUrl };
                        imgPathInfo.Add(page.MenuID, pathInfo);
                    }

                    string img = item.GetFirstImg(pathInfo.Setting);
                    item.Icon = string.IsNullOrWhiteSpace(img) ? string.Empty : pathInfo.UploadUrl + img;
                }

                ViewBag.Recommends2         = recommends;
                ViewBag.RecommendSitePages2 = recommendSitePages;
            }
        }
Ejemplo n.º 2
0
        public ActionResult Next(long siteId, long menuId, int style, int pageIndex, string key, string type, long?typeId)
        {
            ArticleSettingModels setting = ArticleSettingDAO.GetItem(menuId);

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

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

            ViewBag.UploadUrl = WorkV3.Golbal.UpdFileInfo.GetVPathByMenuID(siteId, menuId).TrimEnd('/') + "/";
            ViewBag.Setting   = setting;
            return(View("NextStyle" + style, items));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 最新消息列表, 需傳入Token
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResultWithPage <List <NewsListResult> > Post([FromBody] ArticlesListRequest data)
        {
            ApiResultWithPage <List <NewsListResult> > result = new ApiResultWithPage <List <NewsListResult> >();
            List <NewsListResult> contentItem = new List <NewsListResult>();

            try
            {
                NewsListResultCode rcode = NewsListResultCode.Success;
                if (string.IsNullOrEmpty(data.SiteSN))
                {
                    rcode          = NewsListResultCode.SiteNull;
                    result.Success = false;
                    result.Code    = (int)rcode;
                    result.Message = rcode.GetMessage();
                    return(result);
                }
                if (string.IsNullOrEmpty(data.SN))
                {
                    rcode          = NewsListResultCode.ModuleSNNull;
                    result.Success = false;
                    result.Code    = (int)rcode;
                    result.Message = rcode.GetMessage();
                    return(result);
                }
                long SiteID = GetSiteID(data.SiteSN);
                if (SiteID <= 0)
                {
                    rcode          = NewsListResultCode.SiteNull;
                    result.Success = false;
                    result.Code    = (int)rcode;
                    result.Message = rcode.GetMessage();
                    return(result);
                }
                var menuItem = MenusDAO.GetInfo(SiteID, data.SN);
                if (menuItem == null || menuItem.Id <= 0)
                {
                    rcode          = NewsListResultCode.MenuNull;
                    result.Success = false;
                    result.Code    = (int)rcode;
                    result.Message = rcode.GetMessage();
                    return(result);
                }

                string uploadUrl = Golbal.UpdFileInfo.GetVPathByMenuID(SiteID, menuItem.Id).TrimEnd('/') + "/";

                var setting   = ArticleSettingDAO.GetItem(menuItem.Id);
                int pageIndex = data.Index ?? 1;
                int totalRecord;

                //var types = WorkV3.Areas.Backend.Models.DataAccess.ArticleTypesDAO.GetIssueItems(menuItem.Id);
                //if (types == null || types.Count()<=0)
                //{
                //    result.Success = true;
                //    result.Code = (int)rcode;
                //    result.Message = rcode.GetMessage();
                //    result.Content = contentItem;
                //    return result;
                //}
                string typeCond = "";
                if (data.Types != null && data.Types.Count() > 0)
                {
                    typeCond = string.Join(",", data.Types);
                }
                List <ArticleModels> items = ArticleDAO.GetItems(setting, "", typeCond, null, pageIndex, out totalRecord);
                Dictionary <long, List <ArticleTypesModels> > ItemTypes = ArticleDAO.GetItemTypes(items.Select(item => item.ID));
                foreach (var item in items)
                {
                    #region 文章類別
                    List <ArticleTypes> articleTypesItem = new List <ArticleTypes>();
                    var HasItemTypes = ItemTypes.ContainsKey(item.ID);
                    if (HasItemTypes)
                    {
                        foreach (var type in ItemTypes[item.ID])
                        {
                            articleTypesItem.Add(new ArticleTypes()
                            {
                                Name  = type.Name,
                                Color = GetColorCode(type.Color)
                            });
                        }
                    }
                    #endregion

                    string link = string.Empty;
                    if (item.Type == "link")
                    {
                        link = item.Link;
                    }
                    else if (item.Type == "archive")
                    {
                        if (!string.IsNullOrWhiteSpace(item.Archive))
                        {
                            ResourceFilesModels file = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceFilesModels>(item.Archive);
                            link = uploadUrl + file.FileInfo;
                        }
                    }

                    contentItem.Add(new NewsListResult()
                    {
                        ID           = item.ID,
                        CardNo       = item.CardNo,
                        Type         = item.Type,
                        Title        = item.Title,
                        IssueDate    = item.IssueDate?.ToString("yyyy.MM.dd"),
                        Link         = link,
                        ArticleTypes = articleTypesItem
                    });
                }

                result.Success = true;
                result.Code    = (int)rcode;
                result.Message = rcode.GetMessage();
                result.Content = contentItem;
                return(result);
            }
            catch (Exception ex)
            {
                result.Code    = (int)NewsListResultCode.Exception;
                result.Success = false;
                result.Message = ex.ToString();
            }

            return(result);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        public ActionResult Content(CardsModels model)
        {
            long menuId = CardsDAO.GetMenuID(model.No);
            ArticleSettingModels setting = ArticleSettingDAO.GetItem(menuId);

            ViewBag.Setting = setting;

            ArticleModels item = ArticleDAO.GetItemByCard(model.No);

            item.ReplyCommentSetting = setting;
            IEnumerable <ArticleTypesModels> types = item.GetTypes();

            ViewBag.Types = types;
            IEnumerable <ArticleSeriesModels> series = item.GetSeries();

            ViewBag.Series = series;
            IEnumerable <ArticleCategoryModels> readModeCategories = item.GetCategories(IdentityType);

            ViewBag.ReadModeCategories = readModeCategories;

            string uploadUrl = UpdFileInfo.GetVPathByMenuID(model.SiteID, menuId).TrimEnd('/') + "/";

            RecommendHandler(item.ID, setting, uploadUrl, types);
            RecommendHandler2(item.ID, setting, uploadUrl, types);

            //string key = "AllArticleID_" + menuId;
            //long[] allArticleIds = HttpRuntime.Cache[key] as long[];
            //if(allArticleIds == null) {
            //    allArticleIds = ArticleDAO.GetAllIDs(menuId).ToArray();
            //    HttpRuntime.Cache.Add(key, allArticleIds, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), System.Web.Caching.CacheItemPriority.Normal, null);
            //}
            long[] allArticleIds = ArticleDAO.GetAllIDs(setting).ToArray();
            int    index         = Array.IndexOf(allArticleIds, item.ID);

            ViewBag.ListSitePageIndex = (index / setting.PageSize) + 1;

            if (index <= 0)
            {
                ViewBag.Prev = null;
            }
            else
            {
                ArticleModels prev = ArticleDAO.GetItem(allArticleIds[index - 1]);
                ViewBag.Prev         = prev;
                ViewBag.PrevSitePage = CardsDAO.GetPage(prev.CardNo);
            }

            ViewBag.ListSitePage = MenusDAO.GetListPage(menuId);

            if (index == allArticleIds.Length - 1)
            {
                ViewBag.Next = null;
            }
            else
            {
                ArticleModels next = ArticleDAO.GetItem(allArticleIds[index + 1]);
                ViewBag.Next         = next;
                ViewBag.NextSitePage = CardsDAO.GetPage(next.CardNo);
            }
            SitePage page   = CardsDAO.GetPage(model.No);
            long     pageID = page.PageNo;

            ViewBag.UploadUrl        = uploadUrl;
            ViewBag.SiteID           = model.SiteID;
            ViewBag.SiteSN           = page.SiteSN;
            ViewBag.MenuID           = menuId;
            ViewBag.PageID           = pageID;
            ViewBag.CollectionResult = MemberShipDAO.CheckMemberCollectionExist(pageID);
            ViewBag.CollectionCount  = MemberShipDAO.GetPageCollectionCount(pageID);
            ViewBag.Style            = model.StylesID == 0 ? 1 : model.StylesID;

            ArticleDAO.AddItemClicks(item.ID);

            int    style        = model.StylesID == 0 ? 1 : model.StylesID;
            string ViewFileName = string.Format("~/Views/Article/ContentStyle{0}.cshtml", style);

            if (!System.IO.File.Exists(Server.MapPath(ViewFileName)))
            {
                style = 1;
            }
            ViewFileName = string.Format("~/Views/Article/ContentStyle{0}.cshtml", style);
            return(View(ViewFileName, item));
        }