Exemple #1
0
        public async Task <ActionResult> GetFiles(IFormCollection form, CancellationToken cancellationToken = default)
        {
            try
            {
                //Initialization
                form.TryGetValue("search[value]", out var searches);
                form.TryGetValue("draw", out var draws);
                form.TryGetValue("order[0][column]", out var orders);
                form.TryGetValue("order[0][dir]", out var orderDirections);
                form.TryGetValue("start", out var startRecs);
                form.TryGetValue("length", out var pageSizes);

                var draw     = draws.Count == 0 ? 1 : Convert.ToInt32(draws[0]);
                var search   = searches.Count == 0 ? string.Empty : searches[0];
                var order    = orders.Count == 0 ? string.Empty : orders[0];
                var orderDir = orderDirections.Count == 0 ? string.Empty : orderDirections[0];
                int startRec = startRecs.Count == 0 ? 0: Convert.ToInt32(startRecs[0]);
                int pageSize = pageSizes.Count == 0 ? 10: Convert.ToInt32(pageSizes[0]);


                var files = await _bucketRepository.GetFilesAsync(_awsSetting.BucketName, cancellationToken);


                // Total record count
                var totalRecords = files.Count();
                if (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search))
                {
                    files = files.Where(p => p.Name.Contains(searches[0], StringComparison.OrdinalIgnoreCase) ||
                                        p.Guid.Contains(searches[0], StringComparison.OrdinalIgnoreCase) ||
                                        p.Status.ToString().Contains(searches[0], StringComparison.OrdinalIgnoreCase) ||
                                        p.ETag.Contains(searches[0], StringComparison.OrdinalIgnoreCase))
                            .ToList();
                }

                //apply sorting
                switch (order, orderDir)
                {
                case ("0", "asc"):
                    files = files.OrderBy(x => x.Guid).ToList();
                    break;