Пример #1
0
        public override bool Add(Schedule entity)
        {
            var list = All();


            foreach (var currentSchedule in list)
            {
                if (currentSchedule.Name.Equals(entity.Name))
                {
                    throw new ScheduleWithNameAlreadyExistsException();
                }
            }

            using (ISession session = NHibernateService.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(entity);
                    transaction.Commit();
                }
            }

            NotifyObservers();
            return(true);
        }
Пример #2
0
        private IList <T> getAllAds <T>() where T : Ad
        {
            IList <T> Ads = null;

            using (var session = NHibernateService.OpenSession())
            {
                try
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        Ads = session.QueryOver <T>().List();
                        transaction.Commit();
                    }
                    session.Clear();
                    // session.Close();
                }
                catch (Exception e)
                {
                    Logger.Log(e);
                    return(null);
                }
            }
            // return Ads.OrderBy(o => o.Id).ToList();

            return(Ads);
        }
Пример #3
0
 public IQueryable <T> All()
 {
     using (ISession session = NHibernateService.OpenSession())
     {
         return(session.Query <T>().ToList().AsQueryable());
     }
 }
Пример #4
0
        public override bool Add(VideoWall entity)
        {
            var list = All();

            foreach (var currentVideoWall in list)
            {
                if (currentVideoWall.Location.Equals(entity.Location))
                {
                    throw new VideoWallAtLocationAlreadyExistsException("Video wall already exists in database!");
                }
            }


            using (ISession session = NHibernateService.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(entity);
                    transaction.Commit();
                }
            }

            NotifyObservers();
            return(true);
        }
Пример #5
0
        public void TestTransaction2()
        {
            TestMember m = new TestMember()
            {
                Hehe = DateTime.Now.AddDays(12)
            };

            _ps.Save(m);

            IPersistenceService ps2         = new NHibernateService();
            ITransactionService ts2         = (ITransactionService)ps2;
            TestMember          mConcurrent = ps2.GetById <TestMember, int>(m.ID);

            Assert.AreNotSame(m, mConcurrent);
            var mts = ts2.ExecuteInTransaction(() =>
            {
                mConcurrent.Hehe = DateTime.Today.AddDays(20);
                return(true);
            });

            Assert.AreNotSame(m, mConcurrent);
            try
            {
                m.Hehe = DateTime.Now.AddMinutes(5);
                _ps.Save(m);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(StaleObjectStateException), e.GetType());
            }
        }
Пример #6
0
        private T GetUser <T>(int Id) where T : User
        {
            T User = default(T);

            using (var session = NHibernateService.OpenSession())
            {
                try
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        // User = session.QueryOver<User>().Where(c => c.Id == Id)
                        //    .And(c => c is T).SingleOrDefault();
                        User = (T)session.Get(typeof(T), Id);
                        transaction.Commit();
                    }
                    session.Clear();
                    //session.Close();
                }
                catch (Exception e)
                {
                    Logger.Log(e);
                    return(User);
                }
            }
            return(User);
        }
Пример #7
0
        public override bool Add(Employee entity)
        {
            var list = All();

            foreach (var currentEmployee in list)
            {
                if (currentEmployee.Oib.Equals(entity.Oib))
                {
                    throw new EmployeeWithOibAlreadyExistsException("Employee with this OIB already exists!");
                }
            }


            using (ISession session = NHibernateService.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(entity);
                    transaction.Commit();
                }
            }

            NotifyObservers();
            return(true);
        }
Пример #8
0
        private T GetUser <T>(string Username) where T : User

        {
            T User = default(T);

            using (var session = NHibernateService.OpenSession())
            {
                try
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        User = session.QueryOver <T>().Where(c => c.Username == Username).SingleOrDefault();
                        transaction.Commit();
                    }
                    session.Clear();
                    //session.Close();
                }
                catch (Exception e)
                {
                    Logger.Log(e);
                    return(null);
                }
            }
            return(User);
        }
Пример #9
0
        static void Main()
        {
            ISession _session = NHibernateService.OpenSession();

            IRepositoryFactory  _repositoryFactory = new RepositoryFactory(_session);
            IWindowFormsFactory _formsFactory      = new WindowFormsFactory();

            IUserRepository       _userRepository       = _repositoryFactory.GetUserRepository();
            IInitialRunController _initialRunController = new InitialRunController(_formsFactory, _repositoryFactory);
            IUserController       _userController       = new UserController(_formsFactory, _repositoryFactory);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            List <User> users = _userRepository.GetAllUsers();

            if (users.Count == 0)
            {
                Application.Run(new frmStartCalorieLimitWindow(_initialRunController, _userController, _repositoryFactory));
            }
            else
            {
                IFoodDatabaseController _foodDatabaseController = new FoodDatabaseController(_formsFactory, _repositoryFactory);
                IFoodController         _foodController         = new FoodController(_formsFactory, _repositoryFactory);
                Application.Run(new frmDailyIntakeWindow(_foodDatabaseController, _foodController, _repositoryFactory, users[0]));
            }
        }
Пример #10
0
 public override VideoWall FindBy(int id)
 {
     using (ISession session = NHibernateService.OpenSession())
     {
         return(session
                .Query <VideoWall>().SingleOrDefault(x => x.Id == id));
     }
 }
Пример #11
0
 public T FindBy(Expression <Func <T, bool> > expression)
 {
     using (ISession session = NHibernateService.OpenSession())
     {
         return(session.Query <T>()
                .Where(expression).FirstOrDefault());
     }
 }
Пример #12
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind <INHibernateService>().To <NHibernateService>();
            var nhService = new NHibernateService();

            kernel.Bind <IUserRepository>().To <UserRepository>().WithConstructorArgument("nhs", nhService);
            kernel.Bind <ICourseRepository>().To <CourseRepository>().WithConstructorArgument("nhs", nhService);
            kernel.Bind <IScoreRepository>().To <ScoreRepository>().WithConstructorArgument("nhs", nhService);
            kernel.Bind <IComponentRepository>().To <ComponentRepository>().WithConstructorArgument("nhs", nhService);
        }
Пример #13
0
        public AnwendungskernFacade()
        {
            IPersistenceService persistenceService = new NHibernateService();
            ITransactionService transactionService = (ITransactionService)persistenceService;

            mitarbeiterServices = new MitarbeiterkomponenteFacade(persistenceService, transactionService);
            kundenServices      = new KundenkomponenteFacade(persistenceService, transactionService, mitarbeiterServices as IMitarbeiterServicesFuerKunden);
            kursServices        = new KurskomponenteFacade(persistenceService, transactionService, kundenServices as IKundenServicesFuerKurse, mitarbeiterServices as IMitarbeiterServicesFuerKurse);
            rechnungsServices   = new RechnungskomponenteFacade(persistenceService, transactionService, kursServices as IKursServicesFuerRechnungen);
        }
Пример #14
0
        static void Main()
        {
            NHibernateService.OpenSessionFactory();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            PrijavaForm      form      = new PrijavaForm();
            PrijavaPresenter presenter = new PrijavaPresenter(form, new UnitOfWork());

            form.Show();

            Application.Run();
        }
Пример #15
0
        public override bool Add(RentWall entity)
        {
            using (ISession session = NHibernateService.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(entity);
                    transaction.Commit();
                }
            }

            NotifyObservers();
            return(true);
        }
Пример #16
0
        public bool Delete(T entity)
        {
            using (ISession session = NHibernateService.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(entity);
                    transaction.Commit();
                }
            }

            NotifyObservers();
            return(true);
        }
Пример #17
0
        static void Main()
        {
            ISessionFactory sessionFactory = NHibernateService.OpenSessionFactory();
            //NHibernateService.

            WindowFormsFactory formsFactory      = new WindowFormsFactory();
            IRepositoryFactory repositoryFactory = new RepositoryFactory(sessionFactory);

            MainFormController mainController = new MainFormController(formsFactory, repositoryFactory);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMainWindow(mainController));
        }
Пример #18
0
        static void Main()
        {
            SetProcessDPIAware();

            var currentPath = System.Environment.CurrentDirectory;
            var exists      = File.Exists($"{currentPath}\\Reklamator.db");

            if (!exists)
            {
                NHibernateService.CreateDatabase();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainWindowForm(new MainController()));
        }
Пример #19
0
 public List <Postupak> DohvatiSDetaljimaPostupkePoDatumu(int idVeterinar, DateTime datum)
 {
     using (ISession session = NHibernateService.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             var lista = session.Query <Postupak>().Where(x => x.VrstaPostupka.Veterinar.Id == idVeterinar && x.Datum.Value.Date.Equals(datum.Date))
                         .Fetch(x => x.Zivotinja)
                         .Fetch(x => x.VrstaPostupka)
                         .FetchMany(x => x.Lijeks)
                         .FetchMany(x => x.Bolests)
                         .ToList();
             return(lista);
         }
     }
 }
Пример #20
0
        static void Main()
        {
            ISession session = NHibernateService.OpenSession();

            WindowsFormsFactory _formsFactory    = new WindowsFormsFactory();
            ITeamRepository     _teamRepository  = new TeamRepository(session);
            IGameRepository     _gameRepository  = new GameRepository(session);
            IGroupRepository    _groupRepository = new GroupRepository(session);

            InitialFormController initialFormController =
                new InitialFormController(_formsFactory, _teamRepository, _gameRepository, _groupRepository);

            initialFormController.LoadDefaultModel();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmInitialForm(initialFormController));
        }
Пример #21
0
        static void Main(string[] args)
        {
            var customers = GenerateCustomers(1000);
            var efService = new EfService();

            efService.AddRange(BenchmarkResults, customers);
            efService.Filtering(BenchmarkResults, customers);
            efService.UpdateRange(BenchmarkResults, customers);
            efService.RemoveRange(BenchmarkResults, customers);

            customers = GenerateCustomers(1000);
            var dapperService = new DapperService();

            customers = dapperService.AddRange(BenchmarkResults, customers);
            dapperService.Filtering(BenchmarkResults, customers);
            customers = dapperService.UpdateRange(BenchmarkResults, customers);
            dapperService.RemoveRange(BenchmarkResults, customers);

            customers = GenerateCustomers(1000);
            var linq2DbService = new Linq2DbService();

            customers = linq2DbService.AddRange(BenchmarkResults, customers);
            linq2DbService.Filtering(BenchmarkResults, customers);
            customers = linq2DbService.UpdateRange(BenchmarkResults, customers);
            linq2DbService.RemoveRange(BenchmarkResults, customers);

            customers = GenerateCustomers(1000);
            var nhService = new NHibernateService();

            customers = nhService.AddRange(BenchmarkResults, customers);
            nhService.Filtering(BenchmarkResults, customers);
            customers = nhService.UpdateRange(BenchmarkResults, customers);
            nhService.RemoveRange(BenchmarkResults, customers);

            Console.Clear();
            foreach (var result in BenchmarkResults)
            {
                Console.WriteLine($"{result.Action}\t {result.Entities}\t {result.Performance}");
            }
        }
Пример #22
0
 public bool DeleteUser(User User)
 {
     using (var session = NHibernateService.OpenSession())
     {
         try
         {
             using (var transaction = session.BeginTransaction())
             {
                 session.Delete(User);
                 transaction.Commit();
             }
             session.Clear();
             //session.Close();
         }
         catch (Exception e)
         {
             Logger.Log(e);
             return(false);
         }
     }
     return(true);
 }
Пример #23
0
        static void Main(string[] args)
        {
            AnwendungskernFacade anwendungskern = new AnwendungskernFacade();

            Rezeptionist r = new Rezeptionist()
            {
                Vorname  = "Hee",
                Nachname = "Haa"
            };

            anwendungskern.CreateRezeptionist(r);

            Kunde k = new Kunde()
            {
                Vorname       = "Klaus",
                Nachname      = "Müller",
                Adresse       = new AdresseTyp("Berliner Tor", "7", "22091", "Hamburg"),
                EmailAdresse  = new EmailTyp("*****@*****.**"),
                Geburtsdatum  = new DateTime(1990, 01, 01),
                Kundenstatus  = Kundenstatus.Basic,
                Telefonnummer = "123456"
            };
            //anwendungskern.CreateKunde(k, r.ID);

            AnwendungskernFacade aw2 = new AnwendungskernFacade();

            var k2 = aw2.FindRezeptionistById(r.ID);

            NHibernateService h = new NHibernateService();
            var ma = h.GetAll <Mitarbeiter>();

            var sasdads = h.Query <Kunde>().Count();

            k.AngelegtVon = r;
            h.Save(k);

            Console.ReadLine();
        }
Пример #24
0
        static void Main()
        {
            var nhService = new NHibernateService();

            var userRepository      = new UserRepository(nhService);
            var courseRepository    = new CourseRepository(nhService);
            var componentRepository = new ComponentRepository(nhService);
            var scoreRepository     = new ScoreRepository(nhService);

            var loginService   = new LoginService(userRepository);
            var userServices   = new UserServices(userRepository);
            var courseServices = new CourseServices(courseRepository, userRepository, componentRepository);

            var mainFormController   = new MainFormController(userServices, courseServices);
            var loginFormController  = new LoginFormController(mainFormController, loginService);
            var courseFormController = new CourseFormController(courseServices, userServices);
            var userFormController   = new UserFormController(userServices, courseServices);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var loginForm = new LoginForm(loginFormController);

            var mainForm = new MainForm(
                mainFormController,
                loginFormController,
                courseFormController,
                userFormController);

            Application.Run(loginForm);
            var loginResult = loginForm.LoginResult;

            if (loginResult)
            {
                Application.Run(mainForm);
            }
        }
Пример #25
0
        private IList <T> GetAllUsers <T>() where T : User
        {
            IList <T> Users = null;

            using (var session = NHibernateService.OpenSession())
            {
                try
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        Users = session.QueryOver <T>().List();
                        transaction.Commit();
                    }
                    session.Clear();
                    // session.Close();
                }
                catch (Exception e)
                {
                    Logger.Log(e);
                    return(null);
                }
            }
            return(Users);
        }
Пример #26
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            NHibernateService.OpenSessionFactory();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #27
0
        static void Main(string[] args)
        {
            var nhService = new NHibernateService();

            var userRepository      = new UserRepository(nhService);
            var courseRepository    = new CourseRepository(nhService);
            var componentRepository = new ComponentRepository(nhService);
            var scoreRepository     = new ScoreRepository(nhService);

            #region Seeding

            var lecturer = new Lecturer()
            {
                Email        = "*****@*****.**",
                PasswordHash = EncryptionService.EncryptSHA1("pare"),
                Name         = "Tibor",
                Surname      = "Žukina",
                NationalIdentificationNumber = "12345"
            };
            var administrator = new Administrator()
            {
                Email        = "*****@*****.**",
                PasswordHash = EncryptionService.EncryptSHA1("123abc"),
                Name         = "Željko",
                Surname      = "Baranek",
                NationalIdentificationNumber = "123456"
            };
            var student = new Student()
            {
                Name    = "Zlatko",
                Surname = "Hrastić",
                Email   = "*****@*****.**",
                NationalIdentificationNumber = "343999999",
                StudentIdentificationNumber  = "0036476522",
                CoursesEnrolledIn            = new List <Course>(),
                PasswordHash = EncryptionService.EncryptSHA1("jabuka")
            };

            Component medjuispit = new Component()
            {
                MaximumPoints       = 30,
                MinimumPointsToPass = 0,
                Name = "Međuispit"
            };
            Component zavrsni = new Component()
            {
                MaximumPoints       = 40,
                MinimumPointsToPass = 14,
                Name = "Završni ispit"
            };

            var componentList = new List <Component>();
            componentList.Add(medjuispit);
            componentList.Add(zavrsni);

            Course MockCourse = new Course()
            {
                Id   = 1,
                Name = "Objektno oblikovanje",
                NaturalIdentifier = "ObjOblFER2016OO",
                EctsCredits       = 5,
                Components        = componentList,
                LecturersInCharge = new List <Lecturer>(),
                StudentsEnrolled  = new List <Student>()
            };

            Course MockCourse2 = new Course()
            {
                Id   = 2,
                Name = "Napredni algoritmi i strukture podataka",
                NaturalIdentifier = "NASP-FER-2016OO",
                EctsCredits       = 5,
                Components        = null,
                LecturersInCharge = new List <Lecturer>(),
                StudentsEnrolled  = new List <Student>()
            };

            var score = new Score()
            {
                Component = medjuispit,
                Student   = student,
                Value     = 20
            };

            var service = new UserServices(userRepository);
            service.CreateUser(student);
            service.CreateUser(lecturer);
            service.CreateUser(administrator);

            MockCourse.StudentsEnrolled.Add(student);
            MockCourse.LecturersInCharge.Add(lecturer);

            courseRepository.Create(MockCourse);
            courseRepository.Create(MockCourse2);

            scoreRepository.CreateOrUpdate(score);

            #endregion

            System.Console.WriteLine("Seed successfully completed.");
            System.Console.Read();
        }