コード例 #1
0
        public async Task Execute(Input input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }
            var isEmailExist = await _registerUserService.GetEmailUser(input.Email.ToString());

            var isPhoneExist    = _registerUserService.GetMobileUser(input.Mobile.ToString()).Result;
            var isUserNameExist = await _registerUserService.GetNameUser(input.Name.ToString());

            if (isEmailExist != null)
            {
                _outputHandler.Error("Email Already Exist");
            }
            else if (isPhoneExist != null)
            {
                _outputHandler.Error("MobileNumber Already Exist");
            }
            else if (isUserNameExist != null)
            {
                _outputHandler.Error("UserName Already Exist");
            }
            //var customerId = _registerUserService.Execute(input.Name.ToString(), input.Password.ToString()); //add
            //if (customerId == null || customerId == Guid.Empty) //add
            else if (isEmailExist == null && isPhoneExist == null && isUserNameExist == null)
            {
                var registerOutput = _registerUserService.Execute(input.Name.ToString(), input.Password.ToString()
                                                                  , input.Email.ToString(), input.Mobile.ToString());
                if (registerOutput == null)
                {
                    _outputHandler.Error("An error throw when registering user ID"); //add
                    return;                                                          //add
                }

                var customer = _entityFactory.NewCustomer(registerOutput.CustomerId, input.SSN, input.Name);
                var account  = _entityFactory.NewAccount(customer.Id);

                ICredit credit = account.Deposit(input.InitialAmount);
                if (credit == null)
                {
                    _outputHandler.Error("An error happened when depositing the amount.");
                    return;
                }

                customer.Register(account.Id);

                await _customerRepository.Add(customer);

                await _accountRepository.Add(account, credit);

                Output output = new Output(customer, account, registerOutput.Token);
                _outputHandler.Handle(output);
            }
        }