public async Task <SpartaUser> Create(SpartaUser user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("Lozinka je obavezna.");
            }
            var userExists = _uow.GetREpository <SpartaUser>().Any(x => x.UserName == user.UserName);

            if (userExists)
            {
                throw new ArgumentNullException("Korisničko ime \"" + user.UserName + "\" već postoji.");
            }

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

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            try
            {
                _uow.GetREpository <SpartaUser>().Insert(user);
                await _uow.SaveChangesAsync();

                return(user);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 2
0
        public async Task <User> Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("Password is required");
            }
            var userExists = _uow.GetRepository <User>().Any(x => x.UserName == user.UserName);

            if (userExists)
            {
                throw new ArgumentNullException("Korisničko ime \"" + user.UserName + "\" već postoji!"); //mjenjati
            }
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            try
            {
                _uow.GetRepository <User>().Insert(user);
                await _uow.SaveChangesAsync();

                return(user);
            }
            catch (Exception ex)
            {
                throw;
            }
        }