Beispiel #1
0
 private Competition GetCompetition(int competitionId)
 {
     using (var session = NHibernateFactory.OpenSession())
     {
         return(session.Query <Competition>().FirstOrDefault(c => c.Id == competitionId));
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["Id"];

        if (!string.IsNullOrWhiteSpace(id))
        {
            try
            {
                ISession session = NHibernateFactory.OpenSession();
                using (var transactionScope = session.BeginSaveTransaction())
                {
                    var profile = session.QueryOver <Profile>().Where(x => x.ActivationId == id).SingleOrDefault();
                    if (profile != null)
                    {
                        profile.ActivationId = null;
                        session.Update(profile);
                    }
                    else
                    {
                        throw new ArgumentException("There is no profile with this activationId");
                    }
                    transactionScope.Commit();
                }
                session.Close();
            }
            catch
            {
                lblMessage.Text = "Cannot activate this id";
            }
        }
    }
Beispiel #3
0
        private void RegistreraAnmalan(RegistrationViewModel vm)
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var player      = HamtaPlayer(vm.SpelareId);
                    var competition = HamtaCompetition(vm.TavlingsId);

                    if (player != null && competition != null)
                    {
                        PlayerStatus playerStatus;
                        var          playerStatuses = session.QueryOver <PlayerStatus>().Where(ps => ps.Player.Id == player.Id && ps.Competition.Id == competition.Id).List <PlayerStatus>();
                        if (playerStatuses.Count > 0)
                        {
                            playerStatus = playerStatuses[0];
                        }
                        else
                        {
                            playerStatus = new PlayerStatus();
                        }

                        playerStatus.Competition = competition;
                        playerStatus.Player      = player;
                        playerStatus.Status      = NHibernate.Enums.PlayerCompetitionStatus.Registered;
                        session.SaveOrUpdate(playerStatus);
                        transaction.Commit();
                    }
                }
            }
        }
Beispiel #4
0
        private List <PlayerCompetitionDTO> GetPlayerCompetitions(int spelareId)
        {
            var competitions = new List <Competition>();

            using (var session = NHibernateFactory.OpenSession())
            {
                competitions = session.Query <Competition>().Where(c => c.Date.Year == DateTime.Now.Year).OrderBy(c => c.Date).ToList();
            }

            var playerCompetitons = new List <PlayerCompetitionDTO>();

            foreach (var competition in competitions)
            {
                var pc = new PlayerCompetitionDTO()
                {
                    CompetitionId     = competition.Id,
                    CompetitionName   = competition.Name,
                    CompetitionDate   = competition.Date,
                    Greenfee          = competition.Greenfee,
                    RegistrationOpens = competition.RegistrationOpens
                };
                var player = competition.Players.Where(p => p.Player.Id == spelareId).ToList <PlayerStatus>();
                if (player.Count() > 0)
                {
                    pc.PlayerStatus = player.First().Status;
                }

                playerCompetitons.Add(pc);
            }

            return(playerCompetitons);
        }
Beispiel #5
0
        public ActionResult Standings()
        {
            var vm = new StandingsViewModel();

            // hämta data för tabell
            var standings = new List <Standing>();

            using (var session = NHibernateFactory.OpenSession())
            {
                standings = session.Query <Standing>().Where(s => s.Year == DateTime.Now.Year).ToList();
            }

            foreach (var standing in standings)
            {
                var s = new StandingPlayerDTO()
                {
                    Placering     = standing.Place,
                    Namn          = string.Format("{0} {1}", standing.Player.FirstName, standing.Player.LastName),
                    PDGA          = standing.Player.PdgaNumber,
                    TotalPoang    = standing.TotalPoints,
                    DGT1Placering = standing.DGT1Place,
                    DGT1Poang     = standing.DGT1Points,
                    DGT2Placering = standing.DGT2Place,
                    DGT2Poang     = standing.DGT2Points,
                    DGT3Placering = standing.DGT3Place,
                    DGT3Poang     = standing.DGT3Points,
                    DGT4Placering = standing.DGT4Place,
                    DGT4Poang     = standing.DGT4Points,
                    DGT5Placering = standing.DGT5Place,
                    DGT5Poang     = standing.DGT5Points
                };
                vm.Standings.Add(s);
            }


            // Debug - test ...
            //for (int i = 0; i < 30; i++)
            //{
            //    vm.Standings.Add(new StandingPlayerDTO()
            //    {
            //        Placering = 30-i,
            //        Namn = "Peter Bygde",
            //        PDGA = "8558",
            //        TotalPoang = i + 23,
            //        DGT1Placering = 23,
            //        DGT1Poang = 12,
            //        DGT2Placering = 23,
            //        DGT2Poang = 12,
            //        DGT3Placering = 23,
            //        DGT3Poang = 12,
            //        DGT4Placering = 23,
            //        DGT4Poang = 12,
            //        DGT5Placering = 23,
            //        DGT5Poang = 12
            //    });
            //}

            return(View(vm));
        }
Beispiel #6
0
 private bool SpelareRegistrerad(int competitionId, int playerId)
 {
     using (var session = NHibernateFactory.OpenSession())
     {
         var playerStatuses = session.QueryOver <PlayerStatus>().Where(ps => ps.Player.Id == playerId && ps.Competition.Id == competitionId).List <PlayerStatus>();
         return(playerStatuses.Count > 0);
     }
 }
Beispiel #7
0
        public Competition HamtaCompetition(int id)
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                var competition = session.Get <Competition>(id);

                return(competition);
            }
        }
Beispiel #8
0
        public List <PlayerStatus> HamtaCompetitionPlayers(int id)
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                var competition = session.Get <Competition>(id);

                return(competition != null?competition.Players.ToList() : new List <PlayerStatus>());
            }
        }
Beispiel #9
0
        public static IServiceCollection AddNHibernate(this IServiceCollection services, NHibernateSettings settings)
        {
            ISessionFactory sessionFactory = NHibernateFactory.CreateSessionFactory(settings);

            return(services
                   .AddSingleton(sessionFactory)
                   .AddScoped(_ => sessionFactory.OpenSession())
                   .AddScoped <ITransactional, NHibernateTransactional>());
        }
Beispiel #10
0
        private ISession GetSession()
        {
            //if (NS.Component.NHibernate.NHibernateContext.Current != null)
            //    singletonSession= NS.Component.NHibernate.NHibernateContext.Current.Session;
            //else
            singletonSession = NHibernateFactory.OpenSession();

            return(singletonSession);
        }
        public void Init()
        {
            var factory        = new NHibernateFactory();
            var configuration  = factory.GetConfiguration();
            var sessionFactory = factory.GetSessionFactory();

            _session = sessionFactory.OpenSession();
            new SchemaExport(configuration).Execute(true, true, false, _session.Connection, Console.Out);
        }
Beispiel #12
0
        public WCFNHibernateDataAccessor(DataAccessorConfiguration config)
        {
            this.config = config;
            if (config.IsoLevel != null)
            {
                IsoLevel = config.IsoLevel.Value;
            }

            NHibernateFactory.Initialize(this.config);
        }
Beispiel #13
0
 private void SparaPlayer(Player player)
 {
     using (var session = NHibernateFactory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.SaveOrUpdate(player);
             transaction.Commit();
         }
     }
 }
 public void Init()
 {
     using (var session = NHibernateFactory.OpenSession())
     {
         var keys = session.QueryOver <APIKey>().List();
         foreach (var key in keys)
         {
             cache.Add(key.ApiKey, key);
         }
     }
 }
Beispiel #15
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         ExceptionHandler.Default.EmailFeaturesEnabled = false;
         //HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
         NHibernateFactory.Initialize();
     }
     catch (System.Exception ex)
     {
     }
 }
Beispiel #16
0
 public T GetById(int id)
 {
     try
     {
         using (ISession session = NHibernateFactory.OpenSession())
             return(session.Get <T>(id));
     }
     catch (ADOException ex)
     {
         throw new DatabaseException("GetById " + _typeName + " entity exception.", ex);
     }
 }
Beispiel #17
0
 public IList <T> GetList()
 {
     try
     {
         using (ISession session = NHibernateFactory.OpenSession())
             return(session.CreateCriteria <T>().List <T>());
     }
     catch (ADOException ex)
     {
         throw new DatabaseException("GetList " + _typeName + " entities exception.", ex);
     }
 }
Beispiel #18
0
        private void ConfigureDependencies()
        {
            var factory      = new NHibernateFactory();
            var factoryProxy = new NHibernateFactoryProxy();

            factoryProxy.Initialize(factory.GetConfiguration, factory.GetSessionFactory);

            var nHibernateSession = new NHibernateSession(factoryProxy);

            _uow     = new UoW(nHibernateSession);
            _service = new OrderService(_uow);
        }
Beispiel #19
0
        protected void btn_ADD_Click(object sender, EventArgs e)
        {
            UserAccessMapperService userAccessService = new UserAccessMapperService();
            UserAccessNHibernate    userAccess        = new UserAccessNHibernate();

            Guid newId = Guid.NewGuid();

            //ADD A NEW DISCIPLINE
            userAccess = new UserAccessNHibernate
            {
                ID         = newId,
                USER_ID    = Session["SelectedUserID"].ToString(),
                FIRST_NAME = Session["SelectedUserFirstName"].ToString(),
                LAST_NAME  = Session["SelectedUserLastName"].ToString(),
                SCHOOL_CDE = ddl_SchoolCodes.SelectedValue,
            };

            if (ddl_SchoolCodes.SelectedValue.Length < 2)
            {
                ParentPortlet.ShowFeedback("Please Select a School Code before Saving.");
                return;
            }

            var nHibernateSession = new NHibernateFactory().GetSessionFactory().OpenSession();

            try
            {
                using (var transaction = nHibernateSession.BeginTransaction())
                {
                    nHibernateSession.Save(userAccess);
                    transaction.Commit();

                    ParentPortlet.ShowFeedback(FeedbackType.Success, "Access Successfully Added!");
                }
            }
            catch (Exception exception)
            {
                var msg = PortalUser.Current.IsSiteAdmin
                    ? "Selected Access was not added! Error: " + exception.Message
                    : "Selected Access was not added! ";

                this.ParentPortlet.ShowFeedback(FeedbackType.Error, msg);
                ExceptionManager.Publish(exception);
                return;
            }
            finally
            {
                nHibernateSession.Close();
            }

            InitScreen();
        }
Beispiel #20
0
        public Player HamtaPlayer(long spelareId)
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                var players = session.QueryOver <Player>().Where(p => p.Id == spelareId).List <Player>();
                if (players.Count > 0)
                {
                    return(players[0]);
                }
            }

            return(null);
        }
Beispiel #21
0
        private void DeleteCompetitionResults(int competitionId)
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                var results = session.QueryOver <Result>().Where(r => r.Competition.Id == competitionId).List <Result>();
                foreach (var r in results)
                {
                    session.Delete(r);
                }

                session.Flush();
            }
        }
Beispiel #22
0
        private void DeleteStandings()
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                var standings = session.QueryOver <Standing>().List <Standing>();
                foreach (var s in standings)
                {
                    session.Delete(s);
                }

                session.Flush();
            }
        }
Beispiel #23
0
        public Player HamtaPlayer(string PDGANummer)
        {
            using (var session = NHibernateFactory.OpenSession())
            {
                var players = session.QueryOver <Player>().Where(p => p.PdgaNumber == PDGANummer).List <Player>();
                if (players.Count > 0)
                {
                    return(players[0]);
                }
            }

            return(null);
        }
Beispiel #24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var           session = NHibernateFactory.OpenSession();
        AmazonHandler amazon  = new AmazonHandler(InternalBodyArchitectService.PaymentsManager);

        try
        {
            amazon.ProcessOrderRequest(session, Request.Form, Request);
        }
        catch (Exception ex)
        {
            ExceptionHandler.Default.Process(ex);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var session = NHibernateFactory.OpenSession();
        var payPal  = new TransferujHandler(InternalBodyArchitectService.PaymentsManager);

        try
        {
            payPal.ProcessOrderRequest(session, Request.Form, Context);
        }
        catch (Exception ex)
        {
            ExceptionHandler.Default.Process(ex);
        }
    }
Beispiel #26
0
        public NRepository()
        {
            Assembly ass = Assembly.Load("NHib.Types, Version=1.0.0.0, Culture=neutral, PublicKeyToken=92be0c10c668dbeb");

            Dictionary <string, string> drivers = new Dictionary <string, string> {
                { "connection.provider", ConfigurationManager.AppSettings["nhib-provider"] },                   //NHibernate.Connection.DriverConnectionProvider
                { "connection.driver_class", ConfigurationManager.AppSettings["nhib-driver"] },                 //NHibernate.Driver.MySqlDataDriver
                { "connection.connection_string", ConfigurationManager.AppSettings["nhib-connection_string"] }, //Server=127.0.0.1;database=SrkTestServiceDb;Uid=root;Pwd=;
                { "dialect", ConfigurationManager.AppSettings["nhib-dialect"] } //NHibernate.Dialect.MySQL5Dialect
            };

            factory = new NHibernateFactory(drivers, ass);
            factory.Configure();
        }
Beispiel #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        BodyArchitect.Logger.Log.Write("PayPalOrderProcessing started", TraceEventType.Information, "PayPal");
        var           session = NHibernateFactory.OpenSession();
        PayPalHandler payPal  = new PayPalHandler(InternalBodyArchitectService.PaymentsManager);

        try
        {
            payPal.ProcessOrderRequest(session, Request.Form, Request);
        }
        catch (Exception ex)
        {
            ExceptionHandler.Default.Process(ex);
        }
    }
Beispiel #28
0
        public static IServiceCollection ComposeNHibernateDependencies(this IServiceCollection services)
        {
            services.AddSingleton <INHibernateFactoryProxy, NHibernateFactoryProxy>(
                sp =>
            {
                var nHibernateFactory      = new NHibernateFactory();
                var nHibernateFactoryProxy = new NHibernateFactoryProxy();
                nHibernateFactoryProxy.Initialize(nHibernateFactory.GetConfiguration, nHibernateFactory.GetSessionFactory);

                return(nHibernateFactoryProxy);
            });

            services.AddTransient <INHibernateSession, NHibernateSession>();

            return(services);
        }
        public virtual void createTestFixture()
        {
            Dictionary <string, string> properties = CreatePropertiesForSqlLite();// CreatePropertiesForSqlCE();

            configuration = new Configuration {
                Properties = properties
            };

            ModelMapper mapping = new ModelMapper();

            mapping.AddMappings(typeof(ProfileMapping).Assembly.GetTypes());
            configuration.AddMapping(mapping.CompileMappingForAllExplicitlyAddedEntities());

            sessionFactory = configuration.BuildSessionFactory();
            NHibernateFactory.Initialize(sessionFactory);

            CreateDatabase();
        }
Beispiel #30
0
 public void Remove(T entity)
 {
     try
     {
         using (ISession session = NHibernateFactory.OpenSession())
         {
             using (ITransaction transaction = session.BeginTransaction())
             {
                 session.Delete(entity);
                 transaction.Commit();
             }
         }
     }
     catch (ADOException ex)
     {
         throw new DatabaseException("Remove " + _typeName + " entity exception.", ex);
     }
 }