// 最新訊息 - 新聞 公告 聲明 - 最新消息 public ActionResult AnnouncementLatest(int?page) { //======語系取得======== string langCd = GetLang(); //====================== AnnouncementLatestFilter filter = new AnnouncementLatestFilter() { CurrentPage = page ?? 1, LangCode = langCd }; AnnouncementLatestRepository repo = new AnnouncementLatestRepository(); AnnouncementLatestResult mdoel = repo.GetList(filter); return(View(mdoel)); }
/// <summary> /// 列表 /// </summary> /// <param name="filter"></param> /// <returns></returns> public AnnouncementLatestResult GetList(AnnouncementLatestFilter filter, int?costomPageSize = null, string isIndex = null) { AnnouncementLatestResult result = new AnnouncementLatestResult(); List <AnnouncementLatestData> data = new List <AnnouncementLatestData>(); using (var db = new TCGDB(_connectionString)) { try { var source = db.NEWS .AsEnumerable() .Where(s => (string.IsNullOrEmpty(filter.LangCode) ? true : s.LANG_ID == filter.LangCode) && s.STATUS == "Y" && (filter.TypeID == null ? true : s.CATE_ID == (int)filter.TypeID) && (string.IsNullOrEmpty(isIndex) ? true : s.IS_INDEX == isIndex)) .OrderByDescending(o => o.SORT) //排序大到小、發布日期新到舊、建檔日期新到舊 .ThenByDescending(s => s.N_DATE) .ThenByDescending(d => d.BD_DT) .ToList(); foreach (var item in source) { AnnouncementLatestData temp = new AnnouncementLatestData() { ID = item.ID, Title = item.N_TITLE, Img = GetMainImg(item.ID), CateIDInfo = GetNewsCateByID((int)item.CATE_ID, filter.LangCode), PublishDateString = item.N_DATE.Value.ToString("yyyy-MM-dd"), Content = item.N_DESC.RemoveHtmlAllTags(), BD_DTString = item.BD_DT.Value.ToString("yyyy-MM-dd"), Sort = item.SORT.Value, }; data.Add(temp); } result.Data = data; result = this.ListPagination(ref result, filter.CurrentPage, costomPageSize ?? Convert.ToInt32(PublicMethodRepository.GetConfigAppSetting("DefaultPageSize"))); } catch (Exception ex) { throw ex; } } return(result); }
/// <summary> /// [前台] 列表分頁處理 /// </summary> /// <param name="data"></param> /// <param name="page"></param> /// <returns></returns> public AnnouncementLatestResult ListPagination(ref AnnouncementLatestResult model, int page, int pageSize) { int startRow = 0; PaginationResult paginationResult = null; if (pageSize > 0) { //分頁 startRow = (page - 1) * pageSize; paginationResult = new PaginationResult() { CurrentPage = page, DataCount = model.Data.Count(), PageSize = pageSize, FirstPage = 1, LastPage = model.Data.Count() == 0 ? 1 : Convert.ToInt32(Math.Ceiling((decimal)model.Data.Count() / pageSize)) }; } model.Data = model.Data.Skip(startRow).Take(pageSize).ToList(); model.Pagination = paginationResult; return(model); }
// 最新訊息 - 新聞 公告 聲明 列表 public ActionResult AnnouncementList(int?typeID, int?page) { if (!typeID.HasValue) { return(RedirectToAction("AnnouncementLatest")); } //======語系取得======== string langCd = GetLang(); //====================== AnnouncementLatestFilter filter = new AnnouncementLatestFilter() { CurrentPage = page ?? 1, TypeID = typeID, LangCode = langCd }; AnnouncementLatestRepository repo = new AnnouncementLatestRepository(); AnnouncementLatestResult mdoel = repo.GetList(filter); mdoel.TypeID = (int)filter.TypeID; TempData["CateInfo"] = repo.GetNewsCate(langCd); return(View(mdoel)); }