public BrowseModel(MiniSearchModel searchModel, PaginatedList <Mini> minis) { SearchModel = searchModel; Minis = minis ?? PaginatedList.Empty <Mini>(); Random rand = new Random(); ShowRateResults = (rand.Next(0, 24) == 0); }
public async Task <PaginatedList <MemberHistory> > GetMemberHistory(MemberHistoryQuery query) { if (!query.OperatorId.HasValue) { return(PaginatedList <MemberHistory> .Empty(query.PageIndex, query.PageSize)); } using (var db = databaseManager.GetReadOnlyDatabase(query.OperatorId)) { if (query.TransactionId.HasValue) { var tnxId = query.TransactionId.Value; var historyWithGameUser = await db.GameHistories.Where(trx => trx.GameTransactionId == tnxId) .Select(h => new { h.CreatedOnUtc, h.Bet, h.GameId, h.Id, h.IsFreeGame, h.IsDeleted, h.PlatformType, h.RoundId, h.GameResultType, h.UserId, h.Win, UserName = h.User.Name, GameName = h.Game.Name }).FirstOrDefaultAsync(); var memberHistory = historyWithGameUser == null ? new List <MemberHistory>() : new List <MemberHistory> { new MemberHistory { Bet = historyWithGameUser.Bet, CreatedOnUtc = historyWithGameUser.CreatedOnUtc, GameId = historyWithGameUser.GameId, IsSideBet = false, GameTransactionId = tnxId, GameName = historyWithGameUser.GameName, Id = historyWithGameUser.Id, IsFreeGame = historyWithGameUser.IsFreeGame, IsVoid = historyWithGameUser.IsDeleted, PlatformType = (int)historyWithGameUser.PlatformType, RoundId = historyWithGameUser.RoundId, Type = (int)historyWithGameUser.GameResultType, UserId = historyWithGameUser.UserId, UserName = historyWithGameUser.UserName, Win = historyWithGameUser.Win } }; return(PaginatedList <MemberHistory> .Create(memberHistory, query.PageIndex, query.PageSize)); } else { await query.GetUserId(db); var gamesEnum = ((GameId[])System.Enum.GetValues(typeof(GameId))).Select(c => (int)c).ToList(); var platformTypes = ((PlatformType[])System.Enum.GetValues(typeof(PlatformType))).Select(c => (int)c).ToList(); var gameResultType = ((GameResultType[])System.Enum.GetValues(typeof(GameResultType))).Select(c => (int)c).ToList(); var memberHistories = new List <MemberHistory>(); var gameHistories = new List <GameHistory>(); var gameIds = (query.GameId == null || query.GameId == 0) ? gamesEnum : gamesEnum.Where(i => i == query.GameId.Value).ToList(); var platformIds = string.IsNullOrEmpty(query.PlatformType) ? platformTypes : query.PlatformType.Split(',').Select(int.Parse).ToList(); var gameResultIds = query.GameTransactionType == 0 ? gameResultType : gameResultType.Where(i => i == query.GameTransactionType).ToList(); var sql = db.GameHistories.Where(trx => trx.UserId == query.MemberId && trx.DateTimeUtc >= query.StartDateInUTC && trx.DateTimeUtc <= query.EndDateInUTC); if (gameIds.Count > 0) { sql = sql.Where(trx => gameIds.Contains(trx.GameId)); } if (platformIds.Count > 0) { sql = sql.Where(trx => platformIds.Contains((int)trx.PlatformType)); } if (gameResultIds.Count > 0) { sql = sql.Where(trx => gameResultIds.Contains((int)trx.GameResultType)); } gameHistories = await sql.OrderByDescending(trx => trx.DateTimeUtc) .Skip(query.Offset) .Take(query.PageSize) .ToListAsync(); var historyWithGameUser = gameHistories .Select(h => new { h.GameTransactionId, h.CreatedOnUtc, h.Bet, h.GameId, h.Id, h.IsFreeGame, h.IsDeleted, h.PlatformType, h.RoundId, h.GameResultType, h.UserId, h.Win, UserName = query.MemberName, GameName = ((GameId)h.GameId).ToString() }).ToList(); var listId = historyWithGameUser.Select(hu => hu.GameTransactionId).ToArray(); var profileSideBet = await db.SpinBetProfiles.Where(sb => listId.Contains(sb.GameTransactionId) && sb.IsSideBet).ToListAsync(); var listIdSideBet = profileSideBet.Select(sb => sb.GameTransactionId).ToArray(); foreach (var item in historyWithGameUser) { var isSideBet = listIdSideBet.Contains(item.GameTransactionId); memberHistories.Add(new MemberHistory { Bet = isSideBet ? item.Bet * 2 : item.Bet, CreatedOnUtc = item.CreatedOnUtc, GameId = item.GameId, IsSideBet = false, GameTransactionId = item.GameTransactionId, GameName = item.GameName, Id = item.Id, IsFreeGame = item.IsFreeGame, IsVoid = item.IsDeleted, PlatformType = (int)item.PlatformType, RoundId = item.RoundId, Type = (int)item.GameResultType, UserId = item.UserId, UserName = item.UserName, Win = item.Win }); } return(PaginatedList <MemberHistory> .Create(memberHistories, query.PageIndex, query.PageSize)); } } }