예제 #1
0
        public User Create(User user, string password)
        {
            // validation
            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);

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

            var guidId = (user.GetType() == typeof(Patient)) ?
                         StaticObject.PatientId :
                         StaticObject.CompanyId;

            var getType = user.GetType();

            user.RoleId = guidId;
            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
        public User Create(User user, string password)
        {
            // validation
            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);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.RoleId       = StaticObject.AdminId;
            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }