Ejemplo n.º 1
0
 public void RemoveConnection(String ConnectionId)
 {
     using (var db = new ChessContext())
     {
         var userConnection = db.UserConnections.Single(e => e.Connectionid == ConnectionId);
         db.Entry(userConnection).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public List <UserConnection> GetConnections(String UserId)
        {
            List <UserConnection> userConnections;

            using (var db = new ChessContext())
            {
                userConnections = db.UserConnections.Where(e => e.Userid == UserId).ToList();
            }
            return(userConnections);
        }
Ejemplo n.º 3
0
 public void AddConnection(String UserId, String ConnectionId)
 {
     using (var db = new ChessContext())
     {
         db.UserConnections.Add(new UserConnection()
         {
             Userid = UserId, Connectionid = ConnectionId
         });
         db.SaveChanges();
     }
 }
        public async void DatabaseChangesAreFlaggedFluent()
        {
            //Arrange
            var collection = new SqlSnapshotCollection(Config.ConnectionString);

            collection.ConfigureSchema("Chess"); //this loads table definitions direct from the database schema. In theory no further config should be required

            //In practice, however, some extra configuration settings are needed
            collection.DefineTable("[Chess].[Rating]")
            .IsUnpredictable("RatingDate") //RatingDate is not defaulted to GETDATE() or any of the automatic "get the time" variants. This was deliberate, to illustrate that we can alter the automated decisions.
            .Sort("RatingDate")            //* In a similar vein, a GUID was used as the table key for [Chess].[Rating] to illustrate that GUIDs can be handled, however, when they are the primary key they can
            .Sort("RatingSourceId");       //* randomise the order rows are returned, so we need to force a sort on other fields to make the differences repeatable.

            collection.DefineTable("[Chess].[Player]")
            .Sort("Name");     // As above, we need to sort player data because it has a GUID for a primary key, randomising the order that rows are returned.

            collection.DefineTable("[Chess].[AuditPlayer]")
            .IsReference("PlayerId", "[Chess].[Player]", "PlayerId") //The audit table does not have the player ID defined as a foreign key, so no relationship is defined automatically. We define it manually to make the keys consistent.
            .IsUnpredictable("AuditStartDate")                       //* These dates will match the update timestamp. They are set by a trigger, not a default
            .IsUnpredictable("AuditEndDate")                         //* otherwise unpredictability would have been set automatically.
            .Local("AuditStartDate")                                 //* And they are...
            .Local("AuditEndDate");                                  //* local dates

            collection.DefineTable("[Chess].[AuditRating]")
            .IsReference("PlayerId", "[Chess].[Player]", "PlayerId") //The audit table does not have the player ID defined as a foreign key, so no relationship is defined automatically. We define it manually to make the keys consistent.
            .IsReference("RatingId", "[Chess].[Rating]", "RatingId") //The audit table does not have the Rating Id defined as a foreign key, so no relationship is defined automatically. We define it manually to make the keys consistent.
            .IsUnpredictable("AuditStartDate")                       //* These dates will match the update timestamp. They are set by a trigger, not a default
            .IsUnpredictable("AuditEndDate")                         //* otherwise unpredictability would have been set automatically.
            .IsUnpredictable("RatingDate")                           //*
            .Local("AuditStartDate")                                 //* And they are...
            .Local("AuditEndDate")                                   //* local dates
            .Local("RatingDate");                                    //*

            var builder = collection.Snapshot("before");

            var entities = new ChessContext(Config.ConnectionString);

            //Act
            await _om.AddPlayerAsync("Bill", (ChessObjectMother.ChessDotCom, 1801), (ChessObjectMother.Lichess, 1992));

            await _om.AddPlayerAsync("Ted", (ChessObjectMother.ChessDotCom, 1836), (ChessObjectMother.Lichess, 1918));

            collection.Snapshot("after");

            //Assert
            var output = new Output();

            collection.ReportChanges("before", "after", output);
            output.Report.Verify();
        }
Ejemplo n.º 5
0
        protected override void Seed(ChessContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
        public void Rating_Angriff_Test2()
        {
            var pawn = new Pawn(ChessId.pawn_black_of_bishop_of_king, 5, 5);
            var game = Game.Create(new List <ChessPiece> {
                pawn
            });
            var move          = new Move(pawn, 5, 5, 6, 6);
            var gameAfterMove = game.Move(pawn, 6, 6);
            var ruleSet       = new ChessRuleSet();
            var ctx           = new ChessContext()
            {
                Move = move, GameBeforeMove = game, GameAfterMove = gameAfterMove, NextFriendMoves = new Move[0], NextOpponentMoves = new Move[0]
            };

            var rating = ruleSet.Rating_Angriff(ctx);

            Assert.Equal(0, rating);
        }
        public void EvaluateMove_Test1()
        {
            var pawn   = new Pawn(ChessId.pawn_black_of_bishop_of_king, 5, 5);
            var knight = new Knight(ChessId.knight_white_of_queen, 6, 6);
            var game   = Game.Create(new List <ChessPiece> {
                pawn, knight
            });
            var move          = new Move(pawn, 5, 5, 6, 6);
            var gameAfterMove = game.Move(pawn, 6, 6);
            var ruleSet       = new ChessRuleSet();
            var ctx           = new ChessContext()
            {
                Move = move, GameBeforeMove = game, GameAfterMove = gameAfterMove, NextFriendMoves = new Move[0], NextOpponentMoves = new Move[0]
            };

            var rating = ruleSet.EvaluateMove(ctx);

            Assert.NotEqual(0, rating);
        }
Ejemplo n.º 8
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (ChessContext db = new ChessContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
        public async void DatabaseChangesAreFlagged()
        {
            //Arrange
            var collection = SchemaObjectMother.MakeCollection();

            var entities = new ChessContext(Config.ConnectionString);
            var builder  = collection.Snapshot("before");

            //Act
            await _om.AddPlayerAsync("Bill", (ChessObjectMother.ChessDotCom, 1801), (ChessObjectMother.Lichess, 1992));

            await _om.AddPlayerAsync("Ted", (ChessObjectMother.ChessDotCom, 1836), (ChessObjectMother.Lichess, 1918));

            collection.Snapshot("after");

            //Assert
            var output = new Output();

            collection.ReportChanges("before", "after", output);
            output.Report.Verify();
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer <ChessContext>(null);

                try
                {
                    using (var context = new ChessContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
Ejemplo n.º 11
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    using (var db = new ChessContext())
                    {
                        //  var UsersContext = new ApplicationDbContext();
                        // string uid = UsersContext.Users.ToList().FirstOrDefault(e => e.Email == user.UserName).Id;
                        User newUser = new User()
                        {
                            EMail = user.UserName,
                            UId   = user.Id,
                        };
                        db.Users.Add(newUser);
                        db.SaveChanges();
                    }
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 12
0
 public PlayAIController(ChessContext context, ChessService chessService)
 {
     this.context      = context;
     this.chessService = chessService;
 }
 public ChessController(ChessContext context)
 {
     Context = context;
 }
        public static ChessPiece Ist_aktuelles_Feld_gedeckt(ChessContext ctx)
        {
            var lowestFriend = ctx.NextFriendMoves.Where(move => move.ToX == ctx.Move.FromX && move.ToY == ctx.Move.FromY).Select(m => m.ChessPiece).OrderBy(m => m.Value).FirstOrDefault();

            return(lowestFriend);
        }
        public static ChessPiece Ist_aktueller_Platz_von_Gegner_bedroht(ChessContext ctx)
        {
            var lowestopponent = ctx.NextOpponentMoves.Where(move => move.ToX == ctx.Move.FromX && move.ToY == ctx.Move.FromY).Select(m => m.ChessPiece).OrderBy(m => m.Value).FirstOrDefault();

            return(lowestopponent);
        }
Ejemplo n.º 16
0
 public GamesController(ChessContext context)
 {
     _context = context;
 }
Ejemplo n.º 17
0
 public UserRepository(ChessContext chessContext)
 {
     _chessContext = chessContext;
 }
Ejemplo n.º 18
0
 public GenericRepository(ChessContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }