コード例 #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);
 }
コード例 #2
0
 public void SaveTable(Table table)
 {
     using (var context = new XoContext())
     {
         context.Entry(table).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #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();
     }
 }