예제 #1
0
 public IActionResult Post([FromBody] DataRequest dataRequest)
 {
     //return values.Get("search[value]");
     return(new JsonResult(ReturnCustomersSet(dataRequest).Result.Value));
 }
예제 #2
0
        private async Task <List <List <string> > > getAllItems(DataRequest dataRequest)
        {
            string sortedColumnName            = dataRequest.columns.Find(a => a.data == dataRequest.order[0].column).name;
            List <List <string> > customers    = new List <List <string> >();
            List <Customer>       allCustomers = new List <Customer>();

            if (!_cache.TryGetValue("customers", out allCustomers))
            {
                List <string> endPointsToCall = new List <string>();
                int           itemIDCeiling   = 5000; //ID ceiling for each call

                int totalCallCount = Convert.ToInt32(Math.Ceiling((double)spRequestItemCount / (double)itemIDCeiling));
                for (int x = 0; x < totalCallCount; x++)
                {
                    endPointsToCall.Add($"https://boraakkaya.sharepoint.com/_api/web/lists/getbytitle('HugeList')/items?$select=ID,FirstName,LastName,Position,Status,Birthday&$filter=ID ge {x * itemIDCeiling} and ID lt {(x + 1) * itemIDCeiling}&$top={itemIDCeiling}");
                }

                HttpClient          client      = new HttpClient();
                SPAccessTokenHelper tokenHelper = new SPAccessTokenHelper(_config);
                string spAccessToken            = await tokenHelper.getSharePointAccessToken(_config.GetValue <string>("spSiteURL"));

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", spAccessToken);
                client.DefaultRequestHeaders.Add("Accept", "application/json");

                IEnumerable <Task <List <Customer> > > getItemsQuery = from url in endPointsToCall select getItemsbyEndPoint(url, client);

                Task <List <Customer> >[] customerTasks = getItemsQuery.ToArray();

                List <Customer>[] customerValuesArray = await Task.WhenAll(customerTasks);

                allCustomers = new List <Customer>();
                for (int y = 0; y < customerValuesArray.Length; y++)
                {
                    allCustomers.AddRange(customerValuesArray[y]);
                }
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        // Keep in cache for this time, reset time if accessed.
                                        .SetSlidingExpiration(TimeSpan.FromSeconds(30));

                // Save data in cache.
                _cache.Set("customers", allCustomers, cacheEntryOptions);
            }
            if (dataRequest.order[0].dir == "asc")
            {
                allCustomers = allCustomers.OrderBy(x => x.GetType().GetProperty(sortedColumnName).GetValue(x, null)).ToList <Customer>();
            }
            else
            {
                allCustomers = allCustomers.OrderByDescending(x => x.GetType().GetProperty(sortedColumnName).GetValue(x, null)).ToList <Customer>();
            }
            allRecordsCount = allCustomers.Count;
            recordsFiltered = allCustomers.Count;
            if (dataRequest.search.value != "")
            {
                string searchQuery = dataRequest.search.value;
                allCustomers    = allCustomers.FindAll(a => a.FirstName.Contains(searchQuery, StringComparison.OrdinalIgnoreCase) || a.LastName.Contains(searchQuery, StringComparison.OrdinalIgnoreCase) || a.Status.Contains(searchQuery, StringComparison.OrdinalIgnoreCase) || a.Position.Contains(searchQuery, StringComparison.OrdinalIgnoreCase) || a.Birthday.ToShortDateString().Contains(searchQuery, StringComparison.OrdinalIgnoreCase));
                recordsFiltered = allCustomers.Count;
            }
            List <Customer> dataPaged         = allCustomers.Skip(dataRequest.start).Take(dataRequest.length).ToList <Customer>();
            IEnumerable <List <string> > data = from req in dataPaged select new List <string>()
            {
                req.ID.ToString(), req.FirstName, req.LastName, req.Position, req.Status, req.Birthday.ToShortDateString()
            };

            customers = data.ToList <List <string> >();
            return(customers);
        }