Exemplo n.º 1
0
        // 最新訊息 - 活動寫真 - 各州活動列表
        public ActionResult EventStatesList(int?statesTypeID, int?page)
        {
            if (!statesTypeID.HasValue)
            {
                return(RedirectToAction("EventLatest"));
            }

            //======語系取得========
            string langCd = GetLang();
            //======================

            EventStatesListFilter filter = new EventStatesListFilter()
            {
                CurrentPage = page ?? 1,
                LangCode    = langCd
            };

            statesTypeID = statesTypeID ?? 1;

            EventStatesRepository repo  = new EventStatesRepository();
            EventStatesResult     mdoel = repo.GetList((int)statesTypeID, filter);

            mdoel.StatesTypeID    = (int)statesTypeID;
            TempData["StateInfo"] = repo.GetStatesCateByID((int)statesTypeID, langCd);
            return(View(mdoel));
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public EventStatesResult GetList(int statesTypeID, EventStatesListFilter filter, int?costomPageSize = null, string isIndex = null)
        {
            EventStatesResult      result = new EventStatesResult();
            List <EventStatesData> data   = new List <EventStatesData>();

            using (var db = new TCGDB(_connectionString))
            {
                try
                {
                    var source = db.STATES
                                 .AsEnumerable()
                                 .Where(s => (string.IsNullOrEmpty(filter.LangCode) ? true : s.LANG_ID == filter.LangCode) &&
                                        s.STATUS == "Y" && s.CATE_ID == statesTypeID &&
                                        (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)
                    {
                        EventStatesData temp = new EventStatesData()
                        {
                            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.StatesTypeID = statesTypeID;
                    result.Url          = GetStateVideo(statesTypeID);

                    result.Data = data;
                    result      = this.ListPagination(ref result, filter.CurrentPage, costomPageSize ?? Convert.ToInt32(PublicMethodRepository.GetConfigAppSetting("DefaultPageSize")));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(result);
        }