示例#1
0
        public async Task <int> GetPlayerListCount(PlayersFilterModel filterModel)
        {
            if (filterModel == null)
            {
                filterModel = new PlayersFilterModel();
            }

            return(await _legacyContext.Player2.ApplyFilter(filterModel).CountAsync());
        }
示例#2
0
        public async Task <List <PlayerListEntryViewModel> > GetPlayerList(PlayersFilterModel filterModel)
        {
            if (filterModel == null)
            {
                filterModel = new PlayersFilterModel();
            }

            var players = await _legacyContext.Player2.ApplyFilter(filterModel).ToListAsync();

            var playerListEntryViewModels = players.Select(p => new PlayerListEntryViewModel
            {
                GameType  = p.GameType.ToString(),
                PlayerId  = p.PlayerId,
                Username  = p.Username,
                Guid      = p.Guid,
                IpAddress = p.IpAddress,
                FirstSeen = p.FirstSeen.ToString(CultureInfo.InvariantCulture),
                LastSeen  = p.LastSeen.ToString(CultureInfo.InvariantCulture)
            }).ToList();

            return(playerListEntryViewModels);
        }
        private async Task <IActionResult> GetPlayersAjaxPrivate(PlayersFilterModel.FilterType filterType, GameType?id)
        {
            var reader      = new StreamReader(Request.Body);
            var requestBody = await reader.ReadToEndAsync();

            var model = JsonConvert.DeserializeObject <DataTableAjaxPostModel>(requestBody);

            if (model == null)
            {
                return(BadRequest());
            }

            var filterModel = new PlayersFilterModel
            {
                Filter = filterType
            };

            if (id != null)
            {
                filterModel.GameType = (GameType)id;
            }

            var recordsTotal = await _playersRepository.GetPlayerListCount(filterModel);

            filterModel.FilterString = model.Search?.Value;
            var recordsFiltered = await _playersRepository.GetPlayerListCount(filterModel);

            filterModel.TakeEntries = model.Length;
            filterModel.SkipEntries = model.Start;

            if (model.Order == null)
            {
                filterModel.Order = PlayersFilterModel.OrderBy.LastSeenDesc;
            }
            else
            {
                var orderColumn = model.Columns[model.Order.First().Column].Name;
                var searchOrder = model.Order.First().Dir;

                switch (orderColumn)
                {
                case "gameType":
                    filterModel.Order = searchOrder == "asc" ? PlayersFilterModel.OrderBy.GameTypeAsc : PlayersFilterModel.OrderBy.GameTypeDesc;
                    break;

                case "username":
                    filterModel.Order = searchOrder == "asc" ? PlayersFilterModel.OrderBy.UsernameAsc : PlayersFilterModel.OrderBy.UsernameDesc;
                    break;

                case "firstSeen":
                    filterModel.Order = searchOrder == "asc" ? PlayersFilterModel.OrderBy.FirstSeenAsc : PlayersFilterModel.OrderBy.FirstSeenDesc;
                    break;

                case "lastSeen":
                    filterModel.Order = searchOrder == "asc" ? PlayersFilterModel.OrderBy.LastSeenAsc : PlayersFilterModel.OrderBy.LastSeenDesc;
                    break;
                }
            }

            var playersListEntries = await _playersRepository.GetPlayerList(filterModel);

            return(Json(new
            {
                model.Draw,
                recordsTotal,
                recordsFiltered,
                data = playersListEntries
            }));
        }
示例#4
0
        public static IQueryable <Player2> ApplyFilter(this IQueryable <Player2> players, PlayersFilterModel filterModel)
        {
            if (filterModel.GameType != GameType.Unknown)
            {
                players = players.Where(p => p.GameType == filterModel.GameType).AsQueryable();
            }

            if (filterModel.Filter != PlayersFilterModel.FilterType.None && !string.IsNullOrWhiteSpace(filterModel.FilterString))
            {
                switch (filterModel.Filter)
                {
                case PlayersFilterModel.FilterType.UsernameAndGuid:
                    players = players.Where(p => p.Username.Contains(filterModel.FilterString) ||
                                            p.Guid.Contains(filterModel.FilterString) ||
                                            p.PlayerAlias.Any(a => a.Name.Contains(filterModel.FilterString)))
                              .AsQueryable();
                    break;

                case PlayersFilterModel.FilterType.IpAddress:
                    players = players.Where(p => p.IpAddress.Contains(filterModel.FilterString) ||
                                            p.PlayerIpAddresses.Any(ip => ip.Address.Contains(filterModel.FilterString)))
                              .AsQueryable();
                    break;
                }
            }
            else if (filterModel.Filter == PlayersFilterModel.FilterType.IpAddress)
            {
                players = players.Where(p => p.IpAddress != "" && p.IpAddress != null).AsQueryable();
            }

            switch (filterModel.Order)
            {
            case PlayersFilterModel.OrderBy.UsernameAsc:
                players = players.OrderBy(p => p.Username).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.UsernameDesc:
                players = players.OrderByDescending(p => p.Username).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.FirstSeenAsc:
                players = players.OrderBy(p => p.FirstSeen).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.FirstSeenDesc:
                players = players.OrderByDescending(p => p.FirstSeen).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.LastSeenAsc:
                players = players.OrderBy(p => p.LastSeen).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.LastSeenDesc:
                players = players.OrderByDescending(p => p.LastSeen).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.GameTypeAsc:
                players = players.OrderBy(p => p.GameType).AsQueryable();
                break;

            case PlayersFilterModel.OrderBy.GameTypeDesc:
                players = players.OrderByDescending(p => p.GameType).AsQueryable();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            players = players.Skip(filterModel.SkipEntries).AsQueryable();

            if (filterModel.TakeEntries != 0)
            {
                players = players.Take(filterModel.TakeEntries).AsQueryable();
            }

            return(players);
        }