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()));
                }
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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 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);
        }
Beispiel #5
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);
        }
        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.."));
            }
        }
Beispiel #7
0
        public void ExtractData(IOutputHandler ex, IFetchableHandler ch)
        {
            ex.Start();
            ch.Start();
            string[] tab = new string[Lines.Length * 6];
            int      i   = 0;

            foreach (string line in Lines)
            {
                ch.Handle(new string[1] {
                    line + " pogoda"
                });
                tab[i]     = String.Format("{0:yyyy/MM/dd HH:mm:ss}", DateTime.Now);
                tab[i + 1] = line;

                try
                {
                    tab[i + 2] = ch.GetData("wob_tm").ToString();
                    tab[i + 3] = ch.GetData("wob_pp").ToString();
                    tab[i + 4] = ch.GetData("wob_ws").ToString();
                    tab[i + 5] = "Success";
                }
                catch (DataNotFoundException)
                {
                    tab[i + 5] = "Fail";
                }

                i += 6;
            }

            ex.Handle(tab);
            ex.Finish();
            ch.Finish();
        }
        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);
        }
Beispiel #9
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)
        {
            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);
        }
        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);
            }
        }
Beispiel #12
0
        public async Task Execute(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                outputHandler.NotifyError("Owner does not exist");
                return;
            }

            var todoList = await repository.Get(input);

            outputHandler.Handle(new Output(todoList));
        }
Beispiel #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);
        }
Beispiel #14
0
        public async Task Execute(Input input)
        {
            if (input != null && input.IsValid())
            {
                await repository.Add(new Todo(input.Description, input.Owner));

                outputHandler.Handle(new Output
                {
                    Description = input.Description,
                    Owner       = input.Owner
                });
                return;
            }

            outputHandler.NotifyError("Todo object is not valid.");
        }
Beispiel #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);
        }
Beispiel #16
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);
        }
Beispiel #17
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(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);
        }
        /// <summary>
        /// handle the event
        /// </summary>
        /// <param name="event"></param>
        public void Handle(Event @event)
        {
            var data = _converter.Convert(@event.Data);

            _decorate.Handle(new Event(@event.PipelineId, data));
        }
Beispiel #20
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");
            }
        }