Esempio n. 1
0
        public async Task Seed()
        {
            context.Database.EnsureCreated();

            var user = await userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new GameUser
                {
                    FirstName = "Erik",
                    LastName  = "Sahlmén",
                    UserName  = "******",
                    Email     = "*****@*****.**"
                };

                var result = await userManager.CreateAsync(user, "P@ssw0rd!");

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create default user");
                }
            }

            var gameDefinition = context.GameDefinitions.FirstOrDefault();

            if (gameDefinition == null)
            {
                gameDefinition = new GameDefinition
                {
                    Type        = GameDefintionType.Addition,
                    MinNumber   = 1,
                    MaxNumber   = 10,
                    Rounds      = 10,
                    Status      = GameDefintionStatus.Active,
                    TimeCreated = DateTime.Now,
                    CreatedBy   = user
                };
                context.GameDefinitions.Add(gameDefinition);
            }

            if (!context.Games.Any())
            {
                // Seed some games
                context.Games.Add(new Game
                {
                    User             = user,
                    TimeCreated      = DateTime.Now,
                    GameDefinitionId = gameDefinition.Id,
                    GameDefinition   = gameDefinition,
                    Score            = 8,
                    TimeSecs         = 100
                });
                context.SaveChanges();
            }
        }
 public bool SaveAll()
 {
     return(context.SaveChanges() > 0);
 }