Ejemplo n.º 1
0
        public static void DBinitialize()
        {
            using (ITransaction transaction = NhibernateSessionManager.OpenSession().BeginTransaction())
            {
                mySession.Save(new User {
                    UserName = "******", FirstName = "administrator", LastName = "Administrator", HashedPassword = UserRepository.CalculateHash("admin", "admin"), UserMail = "*****@*****.**", UserRole = User.Role.admin
                });
                mySession.Save(new User {
                    UserName = "******", FirstName = "user", LastName = "User", HashedPassword = UserRepository.CalculateHash("user", "user"), UserMail = "*****@*****.**", UserRole = User.Role.user
                });
                mySession.Save(new User {
                    UserName = "******", FirstName = "visitor", LastName = "Visitor", HashedPassword = UserRepository.CalculateHash("visitor", "visitor"), UserMail = "*****@*****.**", UserRole = User.Role.visitor
                });

                mySession.Save(new Supplier {
                    FirstName = "John", LastName = "Papa", Ids = "12345", Grs = "12345", Tel1 = "123456789", Mob1 = "123456789", Email = "*****@*****.**", LblPrintText = "--"
                });
                mySession.Save(new Supplier {
                    FirstName = "Greek", LastName = "Freak", Ids = "123456", Grs = "123456", Tel1 = "123456789", Mob1 = "123456789", Email = "*****@*****.**", LblPrintText = "--"
                });

                mySession.Save(new Material {
                    Code = "001", Title = "Dole bananas", Description = "", TextBox_1 = "", TextBox_2 = "", Origin = "Ecuador", Type = "cavendish"
                });
                mySession.Save(new Material {
                    Code = "014", Title = "Orsero bananas", Description = "", TextBox_1 = "", TextBox_2 = "", Origin = "Ecuador", Type = "cavendish"
                });

                transaction.Commit();
            };
        }
Ejemplo n.º 2
0
 public T FindById(int id)
 {
     try
     {
         return(NhibernateSessionManager.OpenSession().Load <T>(id));
     }
     catch (Exception ex)
     {
         ((MainWindow)Application.Current.MainWindow).AddExceptionTextMsg(ex.ToString());
         throw;
     }
 }
Ejemplo n.º 3
0
 public IList <T> FindAll()
 {
     try
     {
         return(NhibernateSessionManager.OpenSession().CreateCriteria(typeof(T)).List <T>());
     }
     catch (Exception ex)
     {
         ((MainWindow)Application.Current.MainWindow).AddExceptionTextMsg(ex.ToString());
         throw;
     }
 }
Ejemplo n.º 4
0
 public void Delete(T entity)
 {
     using (ITransaction transaction = NhibernateSessionManager.OpenSession().BeginTransaction())
     {
         try
         {
             var session = NhibernateSessionManager.OpenSession();
             session.Delete(entity);
             transaction.Commit();
             session.Flush();
             session.Clear();
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             ((MainWindow)Application.Current.MainWindow).AddExceptionTextMsg(ex.ToString());
         }
     }
 }