Пример #1
0
        public void Handle(CreateUser command)
        {
            var dbResult = from user in _readContext.Set <User>() where user.Username == command.Username select user;


            if (dbResult.Count() > 0)
            {
                throw new Exception("There is already a user with this username.");
            }


            string hashedPassword = command.Password;             // Crypto.Sha512Hash(command.Password);

            ApplyChange(new UserCreated(command.Id, command.Username, hashedPassword, command.EMail, command.Timezone, command.UserRole));
        }
        public async Task <GetUserByCredentialsResult> Retrieve(GetUserByCredentials query)
        {
            string hashedPassword = query.Password;             // Crypto.Sha512Hash(query.Password);

            //join role in _dataSession.Set<UserRole>() on user.UserRoleId equals role.Id
            var dbResult = from user in _readContext.Set <User>()
                           where user.Username == query.Username && user.PasswordHash == hashedPassword
                           select user;


            if (dbResult.Count() == 0)
            {
                throw new Exception("No user found with the specified data");
            }


            User tryed = dbResult.First();


            return(new GetUserByCredentialsResult {
                User = tryed
            });
        }
        public void it_should_exist_in_the_user_table()
        {
            int userCount = _readContext.Set <User>().Count();

            Assert.Equal(1, userCount);
        }