Example #1
0
        public Result <int> RegisterUser(RegisterCommand command)
        {
            var result = new Result <int>();

            IUser existingUser = _readOnlyRepository.GetUserByEmail(command.Email);

            if (existingUser is null)
            {
                IRole role = _readOnlyRepository.GetRoleById(command.RoleId);
                if (role is null)
                {
                    result.AddError("Role not exist.");
                    return(result);
                }

                var user = new User(command.Name, command.Surname, command.Email, command.CountryIso2, command.DateOfBirth, role.Id, role.Name);
                user.SetPassword(_passwordHasher.HashPassword(user, command.Password));

                result.Data = _writeOnlyRepository.RegisterUser(user);
                return(result);
            }

            result.AddError("User already exist.");
            return(result);
        }