Ejemplo n.º 1
0
 public Registered FindUserById(Guid?playerId)
 {
     using (var context = new XoContext())
     {
         return(context.Players.OfType <Registered>().FirstOrDefault(p => p.Id == playerId));
     }
 }
Ejemplo n.º 2
0
 public Registered FindUserByName(string name)
 {
     using (var context = new XoContext())
     {
         return(context.Players.OfType <Registered>().FirstOrDefault(p => p.Name == name));
     }
 }
Ejemplo n.º 3
0
 public bool Exists(Guid id)
 {
     using (var context = new XoContext())
     {
         return(context.Match.Any(x => x.Id == id));
     }
 }
Ejemplo n.º 4
0
 public Player UserExists(string name, string password)
 {
     using (var context = new XoContext())
     {
         return(context.Players.OfType <Registered>().FirstOrDefault(x => x.Name == name && x.Password == password));
     }
 }
Ejemplo n.º 5
0
 public Table FindTableByName(string name)
 {
     using (var context = new XoContext())
     {
         return(context.Table.Include(x => x.Players).FirstOrDefault(x => x.Name == name));
     }
 }
Ejemplo n.º 6
0
 public bool TableExists(string name)
 {
     using (var context = new XoContext())
     {
         return(context.Table.Any(x => x.Name == name));
     }
 }
Ejemplo n.º 7
0
 public Table FindTableById(Guid tableId)
 {
     using (var context = new XoContext())
     {
         return(context.Table.FirstOrDefault(t => t.Id == tableId));
     }
 }
Ejemplo n.º 8
0
 public Table AddTable(Table table)
 {
     if (string.IsNullOrEmpty(table?.Name))
     {
         throw new ArgumentNullException(nameof(table));
     }
     using (var context = new XoContext())
     {
         if (context.Table.Any(t => t.Name == table.Name))
         {
             return(context.Table.FirstOrDefault(x => x.Name == table.Name));
         }
         var owner = _currentUserUserRepository.GetUserSession();
         table = new Table
         {
             Id      = Guid.NewGuid(),
             Owner   = owner,
             OwnerId = _currentUserUserRepository.GetUserSession()?.Id ?? Guid.Empty,
             Players = new List <Registered> {
                 _currentUserUserRepository.GetUserSession()
             },
             Name = table.Name
         };
         context.Entry(table.Owner).State = EntityState.Unchanged;
         context.Table.Add(table);
         context.SaveChanges();
     }
     return(table);
 }
Ejemplo n.º 9
0
 public void SaveTable(Table table)
 {
     using (var context = new XoContext())
     {
         context.Entry(table).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public List <Table> GetCurrentTables()
 {
     using (var context = new XoContext())
     {
         var tables = context.Table.Include(x => x.Players).Where(x => !x.IsDeleted && x.Players.Count < MaxPlayers).ToList();
         return(tables);
     }
 }
Ejemplo n.º 11
0
 public void AddPlayerToTable(Table table, Registered player)
 {
     using (var context = new XoContext())
     {
         context.Entry(table).State = EntityState.Modified;
         var p = context.Players.OfType <Registered>().FirstOrDefault(x => x.Id == player.Id);
         table.Players.Add(p);
         context.SaveChanges();
     }
 }
Ejemplo n.º 12
0
 public bool UserExists(string name)
 {
     using (var context = new XoContext())
     {
         if (context.Players.OfType <Registered>().Any(x => x.Name == name))
         {
             return(true);
         }
         return(false);
     }
 }
Ejemplo n.º 13
0
 public void Add(Registered player)
 {
     player.Name = player.Name.ToLower().Trim();
     using (var context = new XoContext())
     {
         if (
             context.Players.Any(
                 p => p.Name == player.Name))
         {
             throw new InvalidOperationException("Another user exists with the same name.");
         }
         context.Players.Add(player);
         context.SaveChanges();
     }
 }
Ejemplo n.º 14
0
 public bool UserExists(Guid?playerId)
 {
     if (playerId == null || playerId == Guid.Empty)
     {
         return(false);
     }
     using (var context = new XoContext())
     {
         if (context.Players.OfType <Registered>().Any(x => x.Id == playerId))
         {
             return(true);
         }
         return(false);
     }
 }
Ejemplo n.º 15
0
 public void AddMatch(Match match)
 {
     using (var context = new XoContext())
     {
         if (match.Id == Guid.Empty)
         {
             match.Id = Guid.NewGuid();
         }
         if (context.Match.Any(x => x.Id == match.Id))
         {
             return;
         }
         match.Table = context.Table.FirstOrDefault(x => x.Id == match.TableId);
         context.Match.Add(match);
         context.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public List <PlayerScore> GetTopTen()
 {
     using (var context = new XoContext())
     {
         return
             ((from x in context.PlayerScores
               group x by new { x.PlayerId }
               into gx
               select new
         {
             gx.Key.PlayerId,
             Score = gx.Sum(s => s.Score)
         }).OrderBy(x => x.Score).Take(10).ToList().Select(x => new PlayerScore
         {
             PlayerId = x.PlayerId,
             Score = x.Score
         }).ToList());
     }
 }