Example #1
0
        public void AddPermission(Account account, Permission permission)
        {
            var ap = new AccountPermission {
                                                AccountId = account.AccountId,
                                                Permission = permission
                                            };

            BeginTransaction();
            NHibernateSession.SaveOrUpdate(ap);
        }
        public void CreateDatabaseSchemaFluently()
        {
            Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString("server=.;trusted_connection=yes;database=cxromos"))
                .Mappings(x => x.FluentMappings.AddFromAssemblyOf<Account>())
                .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true))
                .BuildSessionFactory();

            IAccountRepository accountRepository = new AccountRepository();

            const string email = "*****@*****.**";

            var account = new Account {
                FirstName = "ace",
                LastName = "xman",
                Username = "******",
                Email = email,
                Password = "******".Encrypt("ace"),
                CreateDate = DateTime.Now,
                LastUpdateDate = DateTime.Now,
                BirthDate = new DateTime(1974, 9, 6),
                EmailVerified = true
            };

            accountRepository.SaveAccount(account);
            accountRepository.CommitChanges();

            var permissions = new List<Permission> {
                                                       new Permission {Name = "PUBLIC"},
                                                       new Permission {Name = "ADMINISTRATOR"},
                                                       new Permission {Name = "MODERATOR"}
                                                   };

            BeginTransaction();
            foreach (var permission in permissions) {
                NHibernateSession.SaveOrUpdate(permission);
            }
            CommitChanges();

            var ap = new AccountPermission {
                                               AccountId = account.AccountId,
                                               Permission = permissions[0]
                                           };

            BeginTransaction();
            NHibernateSession.SaveOrUpdate(ap);
            CommitChanges();
        }