public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                this.testCompetition =
                    (from competition in databaseSession.Query<Competition>()
                     where competition.Name == CompetitionName
                     select competition).FirstOrDefault();

                if (this.testCompetition == null)
                {
                    // No test competition found
                    this.testCompetition = new Competition
                                               {
                                                   CompetitionType = CompetitionType.Field,
                                                   Name = CompetitionName,
                                                   StartDate = DateTime.Now
                                               };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetition);
                        transaction.Commit();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                var roles = from role in databaseSession.Query<Role>()
                            where role.RoleName == RoleName
                            select role;

                using (var transaction = databaseSession.BeginTransaction())
                {
                    foreach (var role in roles)
                    {
                        databaseSession.Delete(role);
                    }

                    transaction.Commit();
                }
            }
        }
        public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                // Make sure there is a test competition
                this.testCompetition =
                    (from competition in databaseSession.Query<Competition>()
                     where competition.Name == CompetitionName
                     select competition).FirstOrDefault();

                if (this.testCompetition == null)
                {
                    // No test competition found
                    this.testCompetition = new Competition
                    {
                        CompetitionType = CompetitionType.Field,
                        Name = CompetitionName,
                        StartDate = DateTime.Now
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetition);
                        transaction.Commit();
                    }
                }

                // Make sure there is a test club
                this.testClub = (from club in databaseSession.Query<Club>()
                                 where club.Name == ClubName
                                 select club).FirstOrDefault();

                if (this.testClub == null)
                {
                    // No test club found
                    this.testClub = new Club
                    {
                        ClubId = "1-123",
                        Country = "SE",
                        Name = ClubName
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testClub);
                        transaction.Commit();
                    }
                }

                // Clear out the current competitors
                var competitors = from competitor in databaseSession.Query<Competitor>()
                                  where competitor.Competition == this.testCompetition
                                  select competitor;

                using (var transaction = databaseSession.BeginTransaction())
                {
                    foreach (var competitor in competitors)
                    {
                        databaseSession.Delete(competitor);
                    }

                    transaction.Commit();
                }
            }
        }
Ejemplo n.º 4
0
 public void Setup()
 {
     var sqlDatabaseMigrator = new SqlDatabaseMigrator();
     sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// The application start, where everything is setup.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Application_Start(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure();
            this.log.Info("Winshooter web starting.");
            this.winShooterApiHost = new WinShooterApiHost();
            this.winShooterApiHost.Init();

            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);
            this.log.Info("Winshooter web startup complete.");
        }
        public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                this.testCompetition =
                    (from competition in databaseSession.Query<Competition>()
                     where competition.Name == CompetitionName
                     select competition).FirstOrDefault();

                if (this.testCompetition == null)
                {
                    // No test competition found
                    this.testCompetition = new Competition
                                               {
                                                   CompetitionType = CompetitionType.Field,
                                                   Name = CompetitionName,
                                                   StartDate = DateTime.Now
                                               };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetition);
                        transaction.Commit();
                    }
                }

                this.testClub = (from club in databaseSession.Query<Club>()
                                 where club.Name == ClubName
                                 select club).FirstOrDefault();

                if (this.testClub == null)
                {
                    // No test club found
                    this.testClub = new Club
                    {
                        ClubId = "1-123",
                        Country = "SE",
                        Name = ClubName
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testClub);
                        transaction.Commit();
                    }
                }

                using (var transaction = databaseSession.BeginTransaction())
                {
                    foreach (var shooter in (from dbShooter in databaseSession.Query<Shooter>()
                                             where
                                                 dbShooter.Surname == ShooterNameForWriteAndRead
                                                 || dbShooter.Surname == ShoooterNameForDeleteCompetitionAndCascade
                                             select dbShooter).ToArray())
                    {
                        databaseSession.Delete(shooter);
                    }

                    transaction.Commit();
                }
            }
        }
        public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                // Make sure there is a competition
                this.testCompetition =
                    (from competition in databaseSession.Query<Competition>()
                     where competition.Name == CompetitionName
                     select competition).FirstOrDefault();

                if (this.testCompetition == null)
                {
                    // No test competition found
                    this.testCompetition = new Competition
                                               {
                                                   CompetitionType = CompetitionType.Field,
                                                   Name = CompetitionName,
                                                   StartDate = DateTime.Now
                                               };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetition);
                        transaction.Commit();
                    }
                }

                // Clear out all current stations
                var stations = from station in databaseSession.Query<Station>()
                               where station.Competition == this.testCompetition
                               select station;

                if (stations.Any())
                {
                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        foreach (var station in stations)
                        {
                            databaseSession.Delete(station);
                        }

                        transaction.Commit();
                    }
                }
            }
        }
        public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                // Check there is a test competition
                this.testCompetition =
                    (from competition in databaseSession.Query<Competition>()
                     where competition.Name == CompetitionName
                     select competition).FirstOrDefault();

                if (this.testCompetition == null)
                {
                    // No test competition found
                    this.testCompetition = new Competition
                                               {
                                                   CompetitionType = CompetitionType.Field,
                                                   Name = CompetitionName,
                                                   StartDate = DateTime.Now
                                               };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetition);
                        transaction.Commit();
                    }
                }

                // Check there is a test club
                this.testClub =
                    (from club in databaseSession.Query<Club>()
                     where club.Name == ClubName
                     select club)
                        .FirstOrDefault();

                if (this.testClub == null)
                {
                    // No test club found
                    this.testClub = new Club
                                        {
                                            Id = Guid.NewGuid(),
                                            Name = ClubName,
                                            Bankgiro = string.Empty,
                                            ClubId = "123-123",
                                            Country = "SE",
                                            Email = string.Empty,
                                            LastUpdated = DateTime.Now,
                                            Plusgiro = string.Empty
                                        };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testClub);
                        transaction.Commit();
                    }
                }

                // Check there is a test user
                this.testUser =
                    (from user in databaseSession.Query<User>()
                     where user.Givenname == UserName && user.Surname == UserName && user.CardNumber == UserCardNumber
                     select user).FirstOrDefault();

                if (this.testUser == null)
                {
                    this.testUser = new User
                                        {
                                            CardNumber = UserCardNumber,
                                            Surname = UserName,
                                            Givenname = UserName,
                                            ClubId = this.testClub.Id,
                                            Email = string.Empty,
                                            Id = Guid.NewGuid(),
                                            LastLogin = DateTime.Now,
                                            LastUpdated = DateTime.Now,
                                        };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testUser);
                        transaction.Commit();
                    }
                }

                // Check there is a test role
                this.testRole =
                    (from role in databaseSession.Query<Role>() where role.RoleName == RoleName select role)
                        .FirstOrDefault();

                if (this.testRole == null)
                {
                    // There is no test role, create
                    this.testRole = new Role { Id = Guid.NewGuid(), RoleName = RoleName };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testRole);
                        transaction.Commit();
                    }
                }

                // Make sure there are no existing roles
                var userRolesInfos = from userRolesInfo in databaseSession.Query<UserRolesInfo>()
                                     where userRolesInfo.User.Id.Equals(this.testUser.Id)
                                     select userRolesInfo;

                if (userRolesInfos.Any())
                {
                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        foreach (var userRolesInfo in userRolesInfos)
                        {
                            databaseSession.Delete(userRolesInfo);
                        }

                        transaction.Commit();
                    }
                }
            }
        }
        public void Setup()
        {
            var sqlDatabaseMigrator = new SqlDatabaseMigrator();
            sqlDatabaseMigrator.MigrateToLatest(ConfigurationManager.ConnectionStrings["WinShooterConnection"].ConnectionString);

            using (var databaseSession = NHibernateHelper.OpenSession())
            {
                // Make sure there is a test competition
                this.testCompetition =
                    (from competition in databaseSession.Query<Competition>()
                     where competition.Name == CompetitionName
                     select competition).FirstOrDefault();

                if (this.testCompetition == null)
                {
                    // No test competition found
                    this.testCompetition = new Competition
                    {
                        CompetitionType = CompetitionType.Field,
                        Name = CompetitionName,
                        StartDate = DateTime.Now
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetition);
                        transaction.Commit();
                    }
                }

                // Make sure there is a test club
                this.testClub = (from club in databaseSession.Query<Club>()
                                 where club.Name == ClubName
                                 select club).FirstOrDefault();

                if (this.testClub == null)
                {
                    // No test club found
                    this.testClub = new Club
                    {
                        ClubId = "1-123",
                        Country = "SE",
                        Name = ClubName
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testClub);
                        transaction.Commit();
                    }
                }

                // Make sure there is a test station
                this.testStation = (from station in databaseSession.Query<Station>()
                                 where station.Competition == this.testCompetition
                                 select station).FirstOrDefault();

                if (this.testStation == null)
                {
                    // No test club found
                    this.testStation = new Station
                    {
                        Competition = this.testCompetition,
                        Distinguish = false,
                        NumberOfShots = 6,
                        NumberOfTargets = 6,
                        Points = true,
                        StationNumber = 1
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testStation);
                        transaction.Commit();
                    }
                }

                // Make sure there is a test weapon
                this.testWeapon = (from weapon in databaseSession.Query<Weapon>()
                                 where weapon.Manufacturer == WeaponManufacturer
                                 select weapon).FirstOrDefault();

                if (this.testWeapon == null)
                {
                    // No test weapon found
                    this.testWeapon = new Weapon
                    {
                        Caliber = WeaponManufacturer,
                        Class = WeaponClassEnum.A1,
                        LastUpdated = DateTime.Now,
                        Manufacturer = WeaponManufacturer,
                        Model = WeaponManufacturer
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testWeapon);
                        transaction.Commit();
                    }
                }

                // Make sure there is a test patrol
                this.testPatrol =
                    (from patrol in databaseSession.Query<Patrol>()
                     where patrol.Competition == this.testCompetition
                     select patrol).FirstOrDefault();

                if (this.testPatrol == null)
                {
                    this.testPatrol = new Patrol
                    {
                        Competition = this.testCompetition,
                        PatrolClass = PatrolClassEnum.A,
                        PatrolId = 1,
                        StartTime = DateTime.Now,
                        StartTimeDisplay = DateTime.Now
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testPatrol);
                        transaction.Commit();
                    }
                }

                // Make sure there is a test shooter
                this.testShooter = (from shooter in databaseSession.Query<Shooter>()
                                    where
                                        shooter.Competition == this.testCompetition
                                        && shooter.Surname == ShooterSurname
                                        && shooter.Givenname == ShooterGivenname
                                        select shooter).FirstOrDefault();

                if (this.testShooter == null)
                {
                    this.testShooter = new Shooter
                    {
                        Competition = this.testCompetition,
                        CardNumber = "123",
                        Class = ShootersClassEnum.Klass1,
                        Club = this.testClub,
                        Email = string.Empty,
                        Givenname = ShooterGivenname,
                        Surname = ShooterSurname,
                        HasArrived = true,
                        LastUpdated = DateTime.Now
                    };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testShooter);
                        transaction.Commit();
                    }
                }

                // Make sure there is a competitor
                this.testCompetitor = (from competitor in databaseSession.Query<Competitor>()
                                       where competitor.Competition == this.testCompetition
                                       select competitor).FirstOrDefault();

                if (this.testCompetitor == null)
                {
                    // No test competitor found
                    this.testCompetitor = new Competitor
                                              {
                                                  Competition = this.testCompetition,
                                                  FinalShootingPlace = 100,
                                                  Patrol = this.testPatrol,
                                                  PatrolLane = 1,
                                                  Shooter = this.testShooter,
                                                  ShooterClass = ShootersClassEnum.Klass1,
                                                  Weapon = this.testWeapon
                                              };

                    using (var transaction = databaseSession.BeginTransaction())
                    {
                        databaseSession.Save(this.testCompetitor);
                        transaction.Commit();
                    }
                }

                // Clear out the current competitor results
                var competitors = from competitor in databaseSession.Query<CompetitorResult>()
                                  where competitor.Competitor == this.testCompetitor
                                  select competitor;

                using (var transaction = databaseSession.BeginTransaction())
                {
                    foreach (var competitor in competitors)
                    {
                        databaseSession.Delete(competitor);
                    }

                    transaction.Commit();
                }
            }
        }