Outline

Demo: Implement Create User

In the Conduit.Repositories Project, modify the AccountRepository class

Modify RegisterUserAsync method
  • Replace the new User code with a non-existing method called CreateUser
  • Pass the account object as a parameter
  • Use the IDE Tools to create the method
Modify the newly generated CreateUser method
  • Create a variable
    • Type: User
    • Name: user
  • User Mapper to map the properties from
    • account
    • account.Person
  • Return the user object

Here is the code the for the RegisterUserAsync Method:

        public async Task<User> RegisterUserAsync(Register register)
        {
            bool userExist = await UserExistAsync(register);
            if (userExist)
            {
                throw new UserExistException("The email or user name is already in use.");
            }
            Account account = await CreateAccountAsync(register);
            User user = CreateUser(account);
            return user;
        }

Here is the code for the CreateUser Method:

        private User CreateUser(Account account)
        {
            User user = new User();
            Mapper.Map(account, user);
            Mapper.Map(account.Person, user);
            return user;
        }