Beispiel #1
0
        public ReadMarkResult <ActivitysViewModel> GetListByDirection(bool goback, string circleKey, int memberId, int maxResult, Guid pageToken)
        {
            var result = new ReadMarkResult <ActivitysViewModel>();
            var list   = new List <ActivitysViewModel>();

            try
            {
                var db = _uow.DbContext;
                // 取出最新的 maxResult 筆資料
                //list = _uow.ActivitysRepo.GetListByDirection(goback, circleKey, memberId, maxResult, pageToken).ToList();
                var listResult = _uow.ActivitysRepo.GetListByLinQ(goback, circleKey, memberId, maxResult, pageToken);
                if (listResult != null)
                {
                    var memberLastReadActivity = GetMemberLastReadActivity(circleKey, memberId);
                    list = ActivityDetailDataProxy(listResult, maxResult, memberLastReadActivity);

                    result.MaxResult = maxResult;
                    // 更新接口資訊
                    result.Success = true;
                    result.Data    = list.ToArray();
                    list           = list.OrderBy(x => x.Publish_Date).ToList();
                    var middleActivity = list.FirstOrDefault();
                    if (middleActivity != null)
                    {
                        var olderResultActivity = db.Activitys.Where(t => t.ToRoomId == circleKey && t.CardisShow == true && t.Publish_Utc < middleActivity.Publish_Utc && t.Id != middleActivity.Id).OrderByDescending(t => t.Publish_Utc).FirstOrDefault();
                        if (olderResultActivity != null && olderResultActivity.Id != middleActivity.Id)
                        {
                            result.OlderResultToken = Utility.OuterKeyHelper.GuidToPageToken(olderResultActivity.OuterKey);
                        }
                    }
                    //為了取得下一個活動資訊
                    list = list.OrderByDescending(t => t.Publish_Date).ToList();
                    var lastActivity = list.FirstOrDefault();
                    if (goback == false && lastActivity != null)
                    {
                        var nextPageActivity = db.Activitys.Where(t => t.ToRoomId == circleKey && t.CardisShow == true && t.Publish_Utc > lastActivity.Publish_Utc && t.Id != lastActivity.Id).FirstOrDefault();

                        if (nextPageActivity != null && nextPageActivity.Id != lastActivity.Id)
                        {
                            result.NextPageToken    = Utility.OuterKeyHelper.GuidToPageToken(nextPageActivity.OuterKey);
                            result.NewerResultToken = Utility.OuterKeyHelper.GuidToPageToken(nextPageActivity.OuterKey);
                        }
                    }
                }
                else
                {
                    result.Success = true;
                    result.Data    = new List <ActivitysViewModel>().ToArray();
                    result.Message = "目前無任何活動!!!";
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = string.Format("{0}\n\n{1}", ex.Message, ex.StackTrace);
                result.Data    = default(ActivitysViewModel[]);
            }

            return(result);
        }
Beispiel #2
0
        private ReadMarkResult <ActivitysViewModel> SortList(ReadMarkResult <ActivitysViewModel> result, IEnumerable <ActivitysViewModel> list, SortParam param)
        {
            //以id排序(時間序才不會錯亂)
            var temp = result.Data.ToList();

            if (param.Goback)
            {
                result.Data = temp.OrderByDescending(x => x.Publish_Date).ToArray();//舊訊息:前端UI會往上長,因此是由大到小排序(最後長的是最舊的訊息)
            }
            else
            {
                result.Data = temp.OrderBy(x => x.Publish_Date).ToArray();//新訊息:前端UI是往下長,因此是由小到大排序
            }
            return(result);
        }
Beispiel #3
0
        ///// <summary>
        ///// 用於查詢日期
        ///// </summary>
        ///// <param name="circleKey"></param>
        ///// <param name="memberId"></param>
        ///// <param name="maxResult"></param>
        ///// <param name="pageToken"></param>
        ///// <param name="queryDate"></param>
        ///// <returns></returns>
        public ReadMarkResult <ActivitysViewModel> GetQueryDateList(string circleKey, int memberId, int maxResult, Guid pageToken, DateTime?queryDate = null)
        {
            var result = new ReadMarkResult <ActivitysViewModel>();
            var list   = new List <ActivitysViewModel>();

            try
            {
                // 取出最新的 maxResult 筆資料
                list = _uow.ActivitysRepo.GetQueryDateList(circleKey, memberId, maxResult, pageToken).ToList();

                foreach (var item in list)
                {
                    item.sOuterKey = Utility.OuterKeyHelper.GuidToPageToken(item.OuterKey);
                }

                // 更新接口資訊
                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = string.Format("{0}\n\n{1}", ex.Message, ex.StackTrace);
                result.Data    = default(ActivitysViewModel[]);
            }

            bool goback = false; //是否往前取得活動

            var param = new SortParam()
            {
                MaxResult = maxResult,
                MemberId  = memberId,
                CircleKey = circleKey,
                Goback    = goback
            };

            if (queryDate != null)
            {
                param.QueryDateTime = queryDate.Value;
            }

            return(SortList(result, list, param));
        }