#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <IHttpActionResult> Get(string sort   = null,
                                                  string fields = null, string filter = null, int page = 1, int pageSize = maxPageSize)
                #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            try
            {
                if (!base.OnActionExecuting(out HttpStatusCode httpStatusCode, out string message))
                {
                    return(Content(httpStatusCode, message));
                }

                var  fieldList         = GetListByDelimiter(fields);
                bool childrenRequested = false;                 // TODO: set this based upon actual fields requested.

                var filterList = GetListByDelimiter(filter);
                var dbItems    = Repo.GetQueryable_City().AsNoTracking();
                RunCustomLogicAfterGetQueryableList(ref dbItems, ref filterList);
                dbItems = dbItems.ApplyFilter(filterList);
                dbItems = dbItems.ApplySort(sort ?? (typeof(entCSC.City).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)).First().Name);

                if (pageSize > maxPageSize)
                {                 // ensure the page size isn't larger than the maximum.
                    pageSize = maxPageSize;
                }

                var      urlHelper        = new UrlHelper(Request);
                PageData paginationHeader = BuildPaginationHeader(urlHelper, GET_LIST_ROUTE_NAME, page: page, totalCount: dbItems.Count(), pageSize: pageSize, sort: sort);
                HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));

                // return result
                return(Ok(dbItems
                          .Skip(pageSize * (page - 1))
                          .Take(pageSize)
                          .ToList()
                          .Select(x => _factory.CreateDataShapedObject(x, fieldList, childrenRequested))));
            }
            catch (Exception ex)
            {
                Log.LogError(eventId: (int)coreEnums.EventId.Exception_WebApi,
                             exception: ex,
                             message: "Unable to get object via Web API for RequestUri {{RequestUri}}",
                             Request.RequestUri.ToString());

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }

                return(InternalServerError());
            }
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Get(string sort   = null,
                                                  string fields = null, string filter = null, int page = 1, int pageSize = maxPageSize)
        {
            try
            {
                if (!base.OnActionExecuting(out HttpStatusCode httpStatusCode, out string message))
                {
                    return(Content(httpStatusCode, message));
                }

                var  fieldList         = GetListByDelimiter(fields);
                bool childrenRequested = false;                 // TODO: set this based upon actual fields requested.

                var filterList = GetListByDelimiter(filter);
                var dbItems    = Repo.GetQueryable_UserRewardAccountTransactionTypeTranslation().AsNoTracking();
                RunCustomLogicAfterGetQueryableList(ref dbItems, ref filterList);
                dbItems = dbItems.ApplyFilter(filterList);
                dbItems = dbItems.ApplySort(sort ?? (typeof(entQR.UserRewardAccountTransactionTypeTranslation).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)).First().Name);

                if (pageSize > maxPageSize)
                {                 // ensure the page size isn't larger than the maximum.
                    pageSize = maxPageSize;
                }

                var      urlHelper        = new UrlHelper(Request);
                PageData paginationHeader = BuildPaginationHeader(urlHelper, GET_LIST_ROUTE_NAME, page: page, totalCount: dbItems.Count(), pageSize: pageSize, sort: sort);
                HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));

                // return result
                return(Ok(dbItems
                          .Skip(pageSize * (page - 1))
                          .Take(pageSize)
                          .ToList()
                          .Select(x => _factory.CreateDataShapedObject(x, fieldList, childrenRequested))));
            }
            catch (Exception ex)
            {
                Error(message: ex.Message, logMessageType: LogMessageType.Instance.Exception_WebApi, ex: ex);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }

                return(InternalServerError());
            }
        }