public async Task <ActionResult> GetList([FromBody] SortAndFilterInformation sentModel)
        {
            var records = await Repository.GetList(sentModel, true);

            return(Ok(new LoadResult <ApplicationUserDTO>()
            {
                Data = records.Item1.ToArray(), Pages = records.Item2, Message = ""
            }));
        }
        public async Task <IActionResult> GetForExport([FromBody] SortAndFilterInformation sentModel)
        {
            using ExcelPackage package = new();
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("ApplicationUser List");
            //Add the headers
            int col = 0;
            int row = 1;

            col++;
            worksheet.Cells[row, col].Value = "ID";
            col++;
            worksheet.Cells[row, col].Value = "Username";
            col++;
            worksheet.Cells[row, col].Value = "Email";
            col++;
            worksheet.Cells[row, col].Value = "Firstname";
            col++;
            worksheet.Cells[row, col].Value = "Lastname";
            worksheet.Cells[1, 1, 1, col].Style.Font.Bold = true;

            var records = (await Repository.GetList(sentModel, true)).Item1;

            foreach (var item in records)
            {
                row++;
                col = 1;
                worksheet.Cells[row, col].Value = item.Id;
                col++;
                worksheet.Cells[row, col].Value = item.UserName;
                col++;
                worksheet.Cells[row, col].Value = item.Email;
                col++;
                worksheet.Cells[row, col].Value = item.FirstName;
                col++;
                worksheet.Cells[row, col].Value = item.LastName;
            }

            System.IO.MemoryStream fs = new();
            await package.SaveAsAsync(fs);

            return(File(fs.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
        }
        private async Task <(List <ApplicationUserDTO>, double)> DoSortFilterAndPaging(SortAndFilterInformation sentModel, bool doPaging)
        {
            string whereClause = String.Empty;
            IQueryable <ApplicationUser> records = context.Users as DbSet <ApplicationUser>;
            int filteredCount = records.Count();

            if (sentModel != null)
            {
                string[] strings =
                {
                    "username",
                    "email",
                    "lastname",
                    "firstname",
                    ""
                };
                // filtering
                // column search is handled here:0
                if (sentModel.filtered != null)
                {
                    foreach (var item in sentModel.filtered)
                    {
                        if (!String.IsNullOrEmpty(item.value))
                        {
                            if (strings.Contains(item.id))
                            {
                                whereClause = whereClause + item.id + ".Contains(\"" + item.value + "\") &&";
                            }
                            else
                            {
                                whereClause = whereClause + item.id + ".ToString().Contains(\"" + item.value + "\") &&";
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(whereClause))
                    {
                        whereClause   = whereClause[0..^ 2];
 public async Task <(List <ApplicationUserDTO>, double)> GetList(SortAndFilterInformation sortAndFilterInformation, bool doPaging)
 {
     return(await DoSortFilterAndPaging(sortAndFilterInformation, doPaging));
 }