コード例 #1
0
        public ActionResult GetScheduler(int pageIndex, int pageSize, string sortField = "DepartureTime", string sortOrder = "desc")
        {
            IEnumerable <SchedulerDb.ScheduleTbl>    ScheduleList = null;
            IQueryable <SchedulerDb.ScheduleTbl>     Query        = null;
            IEnumerable <SchedulerDb.Model.Schedule> ResultList   = null;

            int itemCount    = 0;
            var param        = sortField;
            var propertyInfo = typeof(SchedulerDb.ScheduleTbl).GetProperty(param);
            int skip         = (pageIndex - 1) * pageSize;

            try
            {
                using (_Repo)
                {
                    Query     = _Repo.GetSchedule();
                    itemCount = Query.Count();

                    switch (sortField)
                    {
                    case "DepartureTime":
                        if (sortOrder == "asc")
                        {
                            ScheduleList = Query.OrderBy(S => S.DepartureTime);
                        }
                        else if (sortOrder == "desc")
                        {
                            ScheduleList = Query.OrderByDescending(S => S.DepartureTime);
                        }
                        break;

                    default:
                        ScheduleList = Query.OrderByDescending(S => S.DepartureTime);
                        break;
                    }

                    ResultList = ScheduleList.Skip(skip)
                                 .Take(pageSize).ToList().Select(T => _ModelMapping.GetSchedule(T));
                }
            }
            catch (Exception ex)
            {
            }

            var Result = new { data = ResultList, itemCount = itemCount };

            return(Json(Result, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public IHttpActionResult GetSchedule()
        {
            List <SchedulerDb.Model.Schedule>        sch        = new List <SchedulerDb.Model.Schedule>();
            IQueryable <SchedulerDb.ScheduleTbl>     Query      = null;
            IEnumerable <SchedulerDb.Model.Schedule> ResultList = null;

            try
            {
                Query      = _Repo.GetSchedule();
                ResultList = Query.ToList().Select(T => _ModelMapping.GetSchedule(T));
            }catch (Exception ex)
            {
            }


            var res = ResultList.AsQueryable();

            return(Ok(new { results = res }));
        }