Exemple #1
0
        public async Task Execute(Input input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            IDebit debit = account.Withdraw(input.Amount);

            if (debit == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not have enough funds to withdraw {input.Amount}.");
                return;
            }

            await _accountRepository.Update(account, debit);

            await _unityOfWork.Save();

            Output output = new Output(
                debit,
                account.GetCurrentBalance()
                );

            _outputHandler.Handle(output);
        }
        public async Task Execute(Input input)
        {
            var user = new IdentityUser
            {
                UserName    = input.UserName,
                Email       = input.Email,
                PhoneNumber = input.PhoneNumber
            };

            var Email = await AuthenticationRepository.FindByEmail(input.Email);

            var Username = await AuthenticationRepository.FindByName(input.UserName);

            var Phone = await AuthenticationRepository.FindByPhoneNumber(input.PhoneNumber);

            if (Email != null)
            {
                OutputHandler.Error("Email Already Exist");
            }
            if (Username != null)
            {
                OutputHandler.Error("Username Already Exist");
            }
            if (Phone != null)
            {
                OutputHandler.Error("Phone number Already Exist");
            }
            else
            {
                var result4 = await AuthenticationRepository.Createuser(user, input.password);

                OutputHandler.Handle(new Output("Registraction Successful.."));
            }
        }
        public async Task Execute(Input input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var customer = _entityFactory.NewCustomer(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);

            _outputHandler.Handle(output);
        }
Exemple #4
0
        public async Task Execute(Input input)
        {
            Guid AccountId;
            var  result = CommonAccess.GetAccessAccount(input.AccountId, _accountRepository, _loginUserService).Result.ToString();

            if (!Guid.TryParse(result, out AccountId))
            {
                _outputHandler.Error(result);
                return;
            }
            IAccount account = await _accountRepository.Get(AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exists or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(input.Amount);

            await _accountRepository.Update(account, credit);

            Output output = new Output(
                credit,
                account.GetCurrentBalance());

            _outputHandler.Handle(output);
        }
        public async Task Execute(Input input)
        {
            Guid AccountId;
            var  result = CommonAccess.GetAccessAccount(input.AccountId, _accountRepository, _loginUserService).Result.ToString();

            if (!Guid.TryParse(result, out AccountId))
            {
                _outputHandler.Error(result);
                return;
            }
            IAccount account = await _accountRepository.Get(AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exists or is already closed.");
                return;
            }

            if (account.IsClosingAllowed())
            {
                await _accountRepository.Delete(account);
            }

            var output = new Output(account);

            _outputHandler.Handle(output);
        }
        public async Task Execute(Input input)
        {
            Guid CustomerId;
            var  result = CommonAccess.GetAccessCustomer(input.CustomerId, _accountRepository, _loginUserService).Result.ToString();

            if (!Guid.TryParse(result, out CustomerId))
            {
                _outputHandler.Error(result);
                return;
            }
            ICustomer customer = await registerUserService.GetCustomer(CustomerId);

            if (customer == null)
            {
                _outputHandler.Error($"The customer {CustomerId} does not exists or is not processed yet.");
                return;
            }

            List <Boundaries.GetCustomerDetails.Account> accounts = new List <Boundaries.GetCustomerDetails.Account>();

            foreach (Guid accountId in customer.Accounts)
            {
                IAccount account = await _accountRepository.Get(accountId);

                if (account != null)
                {
                    Boundaries.GetCustomerDetails.Account accountOutput = new Boundaries.GetCustomerDetails.Account(account);
                    accounts.Add(accountOutput);
                }
            }

            Output output = new Output(customer, accounts);

            _outputHandler.Handle(output);
        }
Exemple #7
0
        public async Task Execute(Input input)
        {
            IAccount originAccount = await _accountRepository.Get(input.OriginAccountId);

            if (originAccount == null)
            {
                _outputHandler.Error($"The account {input.OriginAccountId} does not exist or is already closed.");
                return;
            }

            IAccount destinationAccount = await _accountRepository.Get(input.DestinationAccountId);

            if (destinationAccount == null)
            {
                _outputHandler.Error($"The account {input.DestinationAccountId} does not exist or is already closed.");
                return;
            }

            IDebit  debit  = originAccount.Withdraw(input.Amount);
            ICredit credit = destinationAccount.Deposit(input.Amount);

            await _accountRepository.Update(originAccount, debit);

            await _accountRepository.Update(destinationAccount, credit);

            await _unityOfWork.Save();

            Output output = new Output(
                debit,
                originAccount.GetCurrentBalance(),
                input.OriginAccountId,
                input.DestinationAccountId);

            _outputHandler.Handle(output);
        }
        public async Task Execute(Input input)
        {
            var r1 = new Regex(@"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");
            var r2 = new Regex(@"^([0-9]{10})$");

            if (!string.IsNullOrEmpty(input.UserName) && r1.IsMatch(input.UserName))
            {
                //var result1 = userManager.Users.SingleOrDefault(r => r.Email == model.UserName);

                //return await logincheck(result1, model.password);

                var result1 = await AuthenticationRepository.FindByEmail(input.UserName);

                if (result1 == null)
                {
                    OutputHandler.Error("Email not Found");
                }
                else
                {
                    var output = await logincheck(result1, input.Password);

                    OutputHandler.Handle(new Output(output.ToString()));
                }
            }
            else if (!string.IsNullOrEmpty(input.UserName) && r2.IsMatch(input.UserName))
            {
                //var result2 = userManager.Users.SingleOrDefault(r => r.PhoneNumber == model.UserName);

                //return await logincheck(result2, model.password);

                var result2 = await AuthenticationRepository.FindByPhoneNumber(input.UserName);

                if (result2 == null)
                {
                    OutputHandler.Error("PhoneNumber Not Found");
                }
                else
                {
                    var output1 = await logincheck(result2, input.Password);

                    OutputHandler.Handle(new Output(output1.ToString()));
                }
            }
            else
            {
                var result3 = await AuthenticationRepository.FindByName(input.UserName);

                if (result3 == null)
                {
                    OutputHandler.Error("UserName not Found");
                }
                else
                {
                    var output2 = await logincheck(result3, input.Password);

                    OutputHandler.Handle(new Output(output2.ToString()));
                }
            }
        }
Exemple #9
0
        public async Task Execute(Input input)
        {
            ICustomer customer = await _customerRepository.Get(input.CustomerId);

            if (customer == null)
            {
                _outputHandler.Error($"The customer {input.CustomerId} does not exists or is not processed yet.");
                return;
            }

            List <Boundaries.GetCustomerDetails.Account> accounts = new List <Boundaries.GetCustomerDetails.Account>();

            foreach (Guid accountId in customer.Accounts)
            {
                IAccount account = await _accountRepository.Get(accountId);

                if (account != null)
                {
                    Boundaries.GetCustomerDetails.Account accountOutput = new Boundaries.GetCustomerDetails.Account(account);
                    accounts.Add(accountOutput);
                }
            }

            Output output = new Output(customer, accounts);

            _outputHandler.Handle(output);
        }
Exemple #10
0
        public Task Execute(Input input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            //throw new NotImplementedException();
        }
Exemple #11
0
        public async Task Execute(Input input)
        {
            if (input == null)
            {
                outputHandler.Error("Input is null.");
                return;
            }

            var loginOutput = loginUserService.Execute(input.Name.ToString(), input.Password.ToString());

            if (loginOutput == null)
            {
                outputHandler.Error("An error throw when Login with user password");
                return;
            }

            Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);

            outputHandler.Handle(output);
        }
        public async Task Execute(Input input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var registerOutput = _registerUserService.Execute(input.Name.ToString(), input.Password.ToString());

            if (registerOutput == null)
            {
                _outputHandler.Error("An error throw when registering user ID");
                return;
            }


            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);
        }
Exemple #13
0
        public async Task Execute(Input input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is not processed yet.");
                return;
            }

            Output output = new Output(account);

            _outputHandler.Handle(output);
        }
        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);
            }
        }
Exemple #15
0
        public async Task Execute(Input input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            if (account.IsClosingAllowed())
            {
                await _accountRepository.Delete(account);
            }

            var output = new Output(account);

            _outputHandler.Handle(output);
        }
Exemple #16
0
        public async Task Execute(Input input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exists or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(input.Amount);

            await _accountRepository.Update(account, credit);

            Output output = new Output(
                credit,
                account.GetCurrentBalance());

            _outputHandler.Handle(output);
        }
        public async Task Execute(DepositInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);

            await _unitOfWork.Save();

            DepositOutput output = new DepositOutput(
                credit,
                account.GetCurrentBalance());

            _outputHandler.Default(output);
        }
Exemple #18
0
        public async Task Execute(Input input)
        {
            if (input == null)
            {
                outputHandler.Error("Input is null.");
                return;
            }
            bool IsEmail = Regex.IsMatch(input.Name.ToString(), @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", RegexOptions.IgnoreCase);
            bool IsPhone = Regex.IsMatch(input.Name.ToString(), @"^[0-9]{10}$", RegexOptions.IgnoreCase);

            if (IsEmail)
            {
                var isEmailExist = await loginUserService.GetEmailUser(input.Name.ToString());

                if (isEmailExist != null)
                {
                    var loginOutput = loginUserService.Execute(isEmailExist, input.Password.ToString());
                    if (loginOutput == null)
                    {
                        outputHandler.Error("An error throw when Login with user password");
                        return;
                    }

                    Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);
                    outputHandler.Handle(output);
                }
                else
                {
                    outputHandler.Error("Email Not Found");
                }
            }

            else if (IsPhone)
            {
                var isPhoneExist = await loginUserService.GetMobileUser(input.Name.ToString());

                if (isPhoneExist != null)
                {
                    var loginOutput = loginUserService.Execute(isPhoneExist, input.Password.ToString());
                    if (loginOutput == null)
                    {
                        outputHandler.Error("An error throw when Login with user password");
                        return;
                    }

                    Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);
                    outputHandler.Handle(output);
                }
                else
                {
                    outputHandler.Error("Mobile Number Is Not Found");
                }
            }

            else if (!IsPhone && !IsEmail)
            {
                var isUserNameExist = await loginUserService.GetNameUser(input.Name.ToString());

                if (isUserNameExist != null)
                {
                    var loginOutput = loginUserService.Execute(isUserNameExist, input.Password.ToString());
                    if (loginOutput == null)
                    {
                        outputHandler.Error("An error throw when Login with user password");
                        return;
                    }

                    Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);
                    outputHandler.Handle(output);
                }
                else
                {
                    outputHandler.Error("UserName Is Not Found");
                }
            }
            else
            {
                outputHandler.Error("UnExpected Error");
            }
        }