// 最新訊息 - 活動寫真 - 最新(中央)活動 public ActionResult EventLatest(int?page) { //======語系取得======== string lang_id = GetLang(); //====================== EventLatestListFilter filter = new EventLatestListFilter() { CurrentPage = page ?? 1, LangCode = lang_id }; EventLatestRepository repo = new EventLatestRepository(); EventLatestResult mdoel = repo.GetList(filter); return(View(mdoel)); }
/// <summary> /// 列表 /// </summary> /// <param name="filter"></param> /// <returns></returns> public EventLatestResult GetList(EventLatestListFilter filter, int?customPageSize = null, string isIndex = null) { EventLatestResult result = new EventLatestResult(); List <EventLatestData> data = new List <EventLatestData>(); using (var db = new TCGDB(_connectionString)) { try { var source = db.ACTIVITY .AsEnumerable() .Where(s => (string.IsNullOrEmpty(filter.LangCode) ? true : s.LANG_ID == filter.LangCode) && s.STATUS == "Y" && (string.IsNullOrEmpty(isIndex) ? true : s.IS_INDEX == isIndex)) .OrderByDescending(o => o.SORT) //排序大到小、發布日期新到舊、建檔日期新到舊 .ThenByDescending(s => s.C_DATE) .ThenByDescending(d => d.BD_DT) .ToList(); foreach (var item in source) { EventLatestData temp = new EventLatestData() { ID = item.ID, Title = item.C_TITLE, Img = GetMainImg(item.ID), PagingList = GetPagingListByID(item.ID), PublishDateString = item.C_DATE.Value.ToString("yyyy-MM-dd"), Sort = item.SORT.Value, BD_DTString = item.BD_DT.Value.ToString("yyyy-MM-dd"), }; temp.Remark = GetFirstPagingRemark(temp.PagingList); data.Add(temp); } result.Data = data; result = this.ListPagination(ref result, filter.CurrentPage, customPageSize ?? 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 EventLatestResult ListPagination(ref EventLatestResult 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); }