Exemplo n.º 1
0
        private void BuildSeed(IDbContext _context)
        {
            //_context.BeginTrans();
            var admin = new User
            {
                UserName    = "******",
                Password    = "******",
                DisplayName = "管理员"
            };
            var administrators = new UserRole
            {
                RoleName = "管理员组"
            };

            _userRepo            = StaticResolver.Resolve <IRepository <User> >();
            _userRoleRepo        = StaticResolver.Resolve <IRepository <UserRole> >();
            _userUserRoleMapRepo = StaticResolver.Resolve <IRepository <User_UserRole_Map> >();
            _context.BeginTrans();
            _userRepo.Insert(admin);
            _userRoleRepo.Insert(administrators);
            _context.SaveChanges();
            var relation = new User_UserRole_Map
            {
                UserId     = admin.Id,
                UserRoleId = administrators.Id
            };

            _userUserRoleMapRepo.Insert(relation);
            //_context.SaveChanges();
        }
Exemplo n.º 2
0
 public void BeginTrans()
 {
     if (_trans != null)
     {
         return;
     }
     _context.BeginTrans();
 }