Exemple #1
0
 public static void PopulateTestData(GroupManagementDbContext dbContext)
 {
     dbContext.Groups.Add(new GroupEntity()
     {
         Id = 1, Name = "Group 1"
     });
     dbContext.Groups.Add(new GroupEntity()
     {
         Id = 2, Name = "Group 2"
     });
     dbContext.SaveChanges();
 }
Exemple #2
0
        public User Create(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new Exception("Username \"" + user.Username + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            _context.Users.Add(new UserEntity()
            {
                Id           = user.Id, FirstName = user.FirstName, LastName = user.LastName, Username = user.Username,
                PasswordHash = passwordHash, PasswordSalt = passwordSalt
            });
            _context.SaveChanges();

            return(user);
        }