예제 #1
0
 public UnitOfWork(LvMiniDbContext context, IUserRepository userRepository, ILogRepository logRepository, IProductGroupRepository productGroupRepository)
 {
     _context               = context;
     UserRepository         = userRepository;
     LogRepository          = logRepository;
     ProductGroupRepository = productGroupRepository;
 }
예제 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_context != null)
         {
             _context.Dispose();
             _context = null;
         }
     }
 }
        public static void SeedUsersForContext(this LvMiniDbContext context)
        {
            if (context.Users.Any())
            {
                return;
            }

            List <User> users = new List <User>()
            {
                new User()
                {
                    Username  = "******",
                    Password  = "******",
                    FirstName = "Simeon",
                    LastName  = "Banev",
                    Email     = "*****@*****.**",
                    IsActive  = true,
                    Claims    =
                    {
                        new UserClaim(JwtClaimTypes.Role,       Role.Admin),
                        new UserClaim(JwtClaimTypes.GivenName,  "Simeon"),
                        new UserClaim(JwtClaimTypes.FamilyName, "Banev"),
                        new UserClaim(JwtClaimTypes.Name,       "simo"),
                        new UserClaim(JwtClaimTypes.Email,      "*****@*****.**")
                    }
                },
                new User()
                {
                    Username  = "******",
                    Password  = "******",
                    FirstName = "Gosho",
                    LastName  = "Petrov",
                    Email     = "*****@*****.**",
                    IsActive  = true,
                    Claims    =
                    {
                        new UserClaim(JwtClaimTypes.Role,       Role.User),
                        new UserClaim(JwtClaimTypes.GivenName,  "Gosho"),
                        new UserClaim(JwtClaimTypes.FamilyName, "Petrov"),
                        new UserClaim(JwtClaimTypes.Name,       "gosho"),
                        new UserClaim(JwtClaimTypes.Email,      "*****@*****.**")
                    }
                }
            };

            users[0].Password = Hasher.PasswordHash(users[0], users[0].Password);
            users[1].Password = Hasher.PasswordHash(users[1], users[1].Password);

            context.Users.AddRange(users);
            context.SaveChanges();
        }