public IActionResult UserOnTournament(int?id) { try { var draw = HttpContext.Request.Form["draw"].FirstOrDefault(); // Skip number of Rows count var start = Request.Form["start"].FirstOrDefault(); // Paging Length 10,20 var length = Request.Form["length"].FirstOrDefault(); // Sort Column Name var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault(); // Sort Column Direction (asc, desc) var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault(); // Search Value from (Search box) var searchValue = Request.Form["search[value]"].FirstOrDefault(); //Paging Size (10, 20, 50,100) int pageSize = length != null?Convert.ToInt32(length) : 0; int skip = start != null?Convert.ToInt32(start) : 0; int recordsTotal = 0; // getting all Customer data var tournamentData = _tournamentService.GetAllTournamentAsync().Where(x => x.Id == id.Value); var customerData = tournamentData .SelectMany(x => x.OptinUsers) .Select(x => new { x.User.Id, x.User.Email, x.User.BetclicUserName, NbGoodReponse = x.Tournament.Bets .Where(y => y.User.Id == x.User.Id) .Count(u => u.Selection.Id == x.Tournament.Markets.Single(t => t.Id == u.MarketId).WinningSelectionId), AmountOfWinnings = x.Tournament.Winnables.FirstOrDefault(z => z.NbGoodAnswer == x.Tournament.Bets .Where(y => y.User.Id == x.User.Id) .Count(u => u.Selection.Id == x.Tournament.Markets.Single(t => t.Id == u.MarketId).WinningSelectionId)).AmountOfWinnings }); //Sorting if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection))) { var discountFilterExpression = customerData.GetExpression(sortColumn); customerData = sortColumnDirection == "desc" ? customerData.OrderByDescending(discountFilterExpression) : customerData.OrderBy(discountFilterExpression); } //Search if (!string.IsNullOrEmpty(searchValue)) { customerData = customerData.Where(m => m.BetclicUserName.ToLower().Contains(searchValue.ToLower()) || m.Email.ToLower().Contains(searchValue.ToLower())); } //total number of rows counts recordsTotal = customerData.Count(); //Paging var data = customerData.Skip(skip).Take(pageSize).ToList(); //Returning Json Data return(Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); } catch (Exception) { throw; } }