Exemplo n.º 1
0
        //public async  Task<IList<User>> FindAllUsersAsync()
        //{
        //  List<User> users = await dbContext.Users.ToListAsync();
        //    return users;
        //}
        public async Task AddAccountAsync(string userName, string firstName, string lastName, string password, string accountType, string countryName, string cityName)
        {
            if (String.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("Username cannot be null or empty.");
            }
            if (String.IsNullOrWhiteSpace(password) || password.Length < 6)
            {
                throw new ArgumentException("Password is required and must be at least 6 characters long.");
            }
            if (await this.dbContext.Users.AnyAsync(p => p.UserName == userName))
            {
                throw new ArgumentException("Username is already taken.");
            }

            var user = new User()
            {
                UserName      = userName,
                FirstName     = firstName,
                LastName      = lastName,
                Password      = hasher.Hash(password),
                AccountType   = accountType,
                AccountStatus = "Active",
                Country       = countryName,
                City          = cityName,
            };
            await dbContext.Users.AddAsync(user);

            var userPhoto = new UserPhoto()
            {
                User = user
            };
            await dbContext.UserPhotos.AddAsync(userPhoto);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        private int Hash(String key)
        {
            uint token = hashingFunction.Hash(Encoding.ASCII.GetBytes(key));

            return((int)token);
        }