public IActionResult Participants([FromBody] ParticipantsFilter filter) { var res = tournamentService.GetParticipants(filter); if (!res.IsSuccess) { return(BadRequest(ErrorResult.GetResult(res))); } return(Ok(new ParticipantsViewModel { Participants = res.Data.Item1, Total = res.Data.Item2 })); }
public OperationResult <(List <ParticipantViewModel>, int)> GetParticipants(ParticipantsFilter filter) { return(InvokeOperations.InvokeOperation(() => { var filteredIds = new List <Guid>(); if (!string.IsNullOrEmpty(filter?.Name)) { var tmp = filter.Name.ToLower().Trim(); filteredIds = context.Participants .Where(x => x.TradeAccount != null && x.Name.ToLower().Contains(tmp)) .Select(x => x.Id) .ToList(); if (!filteredIds.Any()) { return (new List <ParticipantViewModel>(), 0); } } var participants = statisticService.GetParticipantsByPlace(filter?.Skip, filter?.Take, filteredIds); if (!participants.Any()) { return (new List <ParticipantViewModel>(), 0); } var total = filteredIds.Any() ? filteredIds.Count : context.Participants.Count(x => x.TradeAccount != null); var query = context.Participants .Include(x => x.TradeAccount) .ThenInclude(x => x.Charts) .Where(x => participants.Contains(x.Id)); var result = query .Select(x => x.ToParticipantViewModel()) .ToList() .OrderBy(x => participants.IndexOf(x.Id)) .ToList(); foreach (var x in result) { x.Place = statisticService.GetParticipantPlace(x.Id); } return (result, total); })); }