public async Task <bool> Handle(IsValidUserRequest message, CancellationToken cancellationToken) { var userQuery = from u in context.AsQueryable <User>() where u.Id == message.UserNameId select u; return(await userQuery.AnyAsync(cancellationToken)); }
public async Task <bool> Handle(UserHasAnyRoleRequest message, CancellationToken cancellationToken) { var userQuery = from u in context.AsQueryable <User>() where u.Id == message.UserNameId from r in u.Roles select r.Name; var userQueryRoleIntercect = userQuery.Intersect(message.Role); return(await userQueryRoleIntercect.AnyAsync(cancellationToken)); }
protected override IEnumerable <ItemLeaderboardDetail> Handle(ItemLeaderboardRequest message) { var query = context.AsQueryable <Item>() .ProjectTo <ItemLeaderboardDetail>(mapper.ConfigurationProvider) .Where(i => i.FormerPlayer.BotId == AIStatics.ActivePlayerBotId) .OrderByDescending(i => i.Item.Level) .ThenByDescending(i => i.ItemXP.Amount) .Take(message.Limit) .Memoize(); return(mapper.Map <IEnumerable <ItemLeaderboardDetail> >(query)); }
public async Task <Unit> Handle(ResetSecurityStamp message, CancellationToken cancellationToken) { var userQuery = from user in context.AsQueryable <UserSecurityStamp>() where user.Id == message.TargetUserNameId select user; var userEntity = await userQuery.FirstAsync(cancellationToken); userEntity.ResetSecurityStamp(message); await context.CommitAsync(); return(new Unit()); }
public override void Execute(IDataContext context) { ContextQuery = ctx => { var lindella = context.AsQueryable <Players.Entities.Player>() .FirstOrDefault(p => p.BotId == AIStatics.LindellaBotId); if (lindella == null) { throw new DomainException($"Could not find Lindella with BotId {AIStatics.LindellaBotId}"); } var wuffie = context.AsQueryable <Players.Entities.Player>().FirstOrDefault(p => p.BotId == AIStatics.WuffieBotId); if (wuffie == null) { throw new DomainException($"Could not find Wuffie with BotId {AIStatics.WuffieBotId}"); } var cutoff = DateTime.UtcNow.AddDays(-3); var query = ctx.AsQueryable <Item>() .Where(i => i.FormerPlayer.BotId == AIStatics.PsychopathBotId && i.Owner != null && (i.Owner.Id == lindella.Id || i.Owner.Id == wuffie.Id) && i.TimeDropped < cutoff) .Include(i => i.Runes) .Include(i => i.FormerPlayer) .Include(i => i.FormerPlayer.Effects) .Include(i => i.FormerPlayer.Skills) .Include(i => i.FormerPlayer.PlayerLogs) .Include(i => i.FormerPlayer.TFEnergies) .Include(i => i.FormerPlayer.TFEnergiesCast) .Take(50) // for performance reasons don't run too many deletions at once, otherwise this command will take forever .ToList(); foreach (var p in query.Select(q => q.FormerPlayer)) { foreach (var x in p.Effects.ToList()) { ctx.Remove(x); } foreach (var x in p.Skills.ToList()) { ctx.Remove(x); } foreach (var x in p.PlayerLogs.ToList()) { ctx.Remove(x); } foreach (var x in p.TFEnergies.ToList()) { ctx.Remove(x); } foreach (var x in p.TFEnergiesCast.ToList()) { ctx.Remove(x); } ctx.Remove(p); } context.Commit(); foreach (var i in query) { i.RemoveRunes(); ctx.Remove(i); } context.Commit(); }; ExecuteInternal(context); }
public override void Execute(IDataContext context) { ContextQuery = ctx => { var player = ctx.AsQueryable <Player>() .Include(p => p.Items) .Include(p => p.Items.Select(i => i.ItemSource)) .SingleOrDefault(cr => cr.User.Id == MembershipId); if (player == null) { throw new DomainException($"Player with MembershipID '{MembershipId}' could not be found"); } if (player.GameMode == GameMode) { throw new DomainException("You are already in this game mode."); } if (player.GameMode == (int)GameModeStatics.GameModes.PvP && player.IsInDungeon()) { throw new DomainException("You cannot switch out of PvP mode while you are in the dungeon."); } if (!Force) { var WhenLastCombat = player.LastCombatTimestamp; //Compare combat time stamps to get the most recent. if (player.LastCombatTimestamp < player.LastCombatAttackedTimestamp) { WhenLastCombat = player.LastCombatAttackedTimestamp; } //Grab dates and get the minutes. var GetCombatMinutes = Math.Abs(Math.Floor(WhenLastCombat.Subtract(DateTime.UtcNow).TotalMinutes)); //Evaluate crap. if (GetCombatMinutes < 30 && player.GameMode == (int)GameModeStatics.GameModes.PvP) { throw new DomainException("You cannot leave PvP mode until you have been out of combat for thirty (30) minutes."); } if ((player.GameMode == (int)GameModeStatics.GameModes.Protection || player.GameMode == (int)GameModeStatics.GameModes.Superprotection) && GameMode == (int)GameModeStatics.GameModes.PvP) { throw new DomainException("You cannot switch into that mode during regular gameplay."); } //Remove a player's Dungeon Points whenever they switch into P/SP player.ClearPvPScore(); } var itemGameMode = GameMode; if (itemGameMode == (int)GameModeStatics.GameModes.Superprotection) { itemGameMode = (int)GameModeStatics.GameModes.Protection; } ChangeItemsAndRunesMode(player.Items, itemGameMode); var soulboundItems = context.AsQueryable <Item>() .Where(i => i.SoulboundToPlayer != null && i.SoulboundToPlayer.Id == player.Id) .ToList(); ChangeItemsAndRunesMode(soulboundItems, itemGameMode); player.ChangeGameMode(GameMode); ctx.Commit(); }; ExecuteInternal(context); }