public async Task <List <ChatLogDto> > GetChatLogs(ChatLogFilterModel filterModel)
        {
            if (filterModel == null)
            {
                filterModel = new ChatLogFilterModel();
            }

            var chatLogs = await _legacyContext.ChatLogs.ApplyFilter(filterModel).ToListAsync();

            var results = new List <ChatLogDto>();

            foreach (var chatLog in chatLogs)
            {
                results.Add(new ChatLogDto
                {
                    ChatLogId  = chatLog.ChatLogId,
                    PlayerId   = chatLog.PlayerPlayerId,
                    ServerId   = chatLog.GameServerServerId,
                    ServerName = chatLog.GameServerServer.Title,
                    GameType   = chatLog.GameServerServer.GameType.ToString(),
                    Timestamp  = chatLog.Timestamp,
                    Username   = chatLog.Username,
                    ChatType   = chatLog.ChatType.ToString(),
                    Message    = chatLog.Message
                });
            }

            return(results);
        }
        public async Task <int> GetChatLogCount(ChatLogFilterModel filterModel)
        {
            if (filterModel == null)
            {
                filterModel = new ChatLogFilterModel();
            }

            return(await _legacyContext.ChatLogs.ApplyFilter(filterModel).CountAsync());
        }
Beispiel #3
0
        private async Task <IActionResult> GetChatLogPrivate(GameType?gameType, Guid?serverId, Guid?playerId)
        {
            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 ChatLogFilterModel();

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

            if (serverId != null)
            {
                filterModel.ServerId = (Guid)serverId;
            }

            if (playerId != null)
            {
                filterModel.PlayerId = (Guid)playerId;
            }

            var recordsTotal = await _chatLogsRepository.GetChatLogCount(filterModel);

            filterModel.FilterString = model.Search?.Value;
            var recordsFiltered = await _chatLogsRepository.GetChatLogCount(filterModel);

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

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

                switch (orderColumn)
                {
                case "timestamp":
                    filterModel.Order = searchOrder == "asc" ? ChatLogFilterModel.OrderBy.TimestampAsc : ChatLogFilterModel.OrderBy.TimestampDesc;
                    break;
                }
            }

            var mapListEntries = await _chatLogsRepository.GetChatLogs(filterModel);

            return(Json(new
            {
                model.Draw,
                recordsTotal,
                recordsFiltered,
                data = mapListEntries
            }));
        }
Beispiel #4
0
        public static IQueryable <ChatLogs> ApplyFilter(this IQueryable <ChatLogs> chatLogs, ChatLogFilterModel filterModel)
        {
            chatLogs = chatLogs.Include(cl => cl.GameServerServer).AsQueryable();

            if (filterModel.GameType != GameType.Unknown)
            {
                chatLogs = chatLogs.Where(m => m.GameServerServer.GameType == filterModel.GameType).AsQueryable();
            }

            if (filterModel.ServerId != Guid.Empty)
            {
                chatLogs = chatLogs.Where(m => m.GameServerServerId == filterModel.ServerId).AsQueryable();
            }

            if (filterModel.PlayerId != Guid.Empty)
            {
                chatLogs = chatLogs.Where(m => m.PlayerPlayerId == filterModel.PlayerId).AsQueryable();
            }

            if (!string.IsNullOrWhiteSpace(filterModel.FilterString))
            {
                chatLogs = chatLogs.Where(m => m.Message.Contains(filterModel.FilterString) ||
                                          m.Username.Contains(filterModel.FilterString)).AsQueryable();
            }

            switch (filterModel.Order)
            {
            case ChatLogFilterModel.OrderBy.TimestampAsc:
                chatLogs = chatLogs.OrderBy(cl => cl.Timestamp).AsQueryable();
                break;

            case ChatLogFilterModel.OrderBy.TimestampDesc:
                chatLogs = chatLogs.OrderByDescending(cl => cl.Timestamp).AsQueryable();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

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

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

            return(chatLogs);
        }