private static void SeedAdmins(_AppDbContext context) { if (context.Admins.Any()) { return; } var accountStatusValues = Enum.GetValues(typeof(AccountStatus)); context.Add(new Admin { Id = RandomGenerator.GenerateUUID(), FirstName = "Pro", LastName = "Dev", Email = "*****@*****.**", AdminAccountStatusId = AccountStatus.Active }); context.Admins.AddRange(Enumerable.Range(1, 5).Select(index => new Admin { Id = RandomGenerator.GenerateUUID(), FirstName = RandomGenerator.GenerateName(), LastName = RandomGenerator.GenerateName(), Email = RandomGenerator.GenerateEmail(index), AdminAccountStatusId = (AccountStatus)accountStatusValues.GetValue(RandomGenerator.GenerateNumber(accountStatusValues.Length)), })); context.SaveChanges(); }
public Admin Create(Admin admin, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (_context.Admins.Any(x => x.Email == admin.Email)) { throw new AppException("Email \"" + admin.Email + "\" is already taken"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); admin.PasswordHash = passwordHash; admin.PasswordSalt = passwordSalt; _context.Admins.Add(admin); _context.SaveChanges(); return(admin); }
private static void SeedAdminAccountStatus(_AppDbContext context) { if (context.AdminAccountStatuses.Any()) { return; } Array accountStatusValues = Enum.GetValues(typeof(AccountStatus)); context.AdminAccountStatuses.AddRange(Enumerable.Range(0, accountStatusValues.Length).Select(index => new AdminAccountStatus { AccountStatus = (AccountStatus)accountStatusValues.GetValue(index), Description = ((AccountStatus)accountStatusValues.GetValue(index)).ToName() })); context.SaveChanges(); }
public virtual void Save() { _context.SaveChanges(); }