Example #1
0
        public static async Task Initialize(ApplicationDbContext applicationDbContext, IFunctionalSvc functionalSvc)
        {
            // Check, if db ApplicationDbContext is created
            await applicationDbContext.Database.EnsureCreatedAsync();

            // Check, if db contains any users. If db is not empty, then db has been already seeded
            if (applicationDbContext.Users.Any())
            {
                return;
            }

            // If empty create Default User
            await applicationDbContext.Users.AddAsync(new User { FirstName = "Tâm", UserName = "******", Password = functionalSvc.GetMd5Hash(MD5.Create(), "12345").Result, UserType = "Admin" });

            await applicationDbContext.Users.AddAsync(new User { FirstName = "Tâm 2", UserName = "******", Password = functionalSvc.GetMd5Hash(MD5.Create(), "123").Result, UserType = "User" });

            await applicationDbContext.SaveChangesAsync();
        }
Example #2
0
        User AuthenticateUser(User loginCredentials)
        {
            User user = _db.Users.FirstOrDefault(x => x.UserName == loginCredentials.UserName && x.Password == _functionalSvc.GetMd5Hash(MD5.Create(), loginCredentials.Password).Result);

            return(user);
        }