Exemple #1
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);
 }
Exemple #2
0
 public void SaveTable(Table table)
 {
     using (var context = new XoContext())
     {
         context.Entry(table).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemple #3
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();
     }
 }
Exemple #4
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();
     }
 }
Exemple #5
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();
     }
 }