Пример #1
0
        public async void Test_RegisterAccountAsync()
        {
            var options = new RegisterAccountOptions()
            {
                Currency    = "EUR",
                Description = "Logariasmos gia to paidi"
            };

            var account = await _account.RegisterAccountAsync(1, options);

            Assert.NotNull(account);
        }
Пример #2
0
        public void Add_New_Account_With_DI()
        {
            var options = new RegisterAccountOptions()
            {
                AccountDescr  = "Personal Acount",
                AccountNumber = "8892-511-1031",
                Currency      = "USD"
            };
            var account = _account.Register(1006, options);

            Assert.NotNull(account);
        }
Пример #3
0
        public async Task <Result <Account> > RegisterAccountAsync(int customerId, RegisterAccountOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.Currency))
            {
                return new Result <Account>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = $"Currency is empty!"
                       }
            }
            ;

            if (string.IsNullOrWhiteSpace(options.Description))
            {
                return new Result <Account>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = $"Einai ipoxreotiko na doseis perigrafi"
                       }
            }
            ;


            var customer = (await _customer.GetCustomerByIdAsync(customerId)).Data;

            if (customer != null)
            {
                var account = new Account()
                {
                    Currency    = options.Currency,
                    Description = options.Description
                };

                customer.Accounts.Add(account);

                _dBContext.Update <Customer>(customer);
                await _dBContext.SaveChangesAsync();

                return(new Result <Account>()
                {
                    Code = ResultCodes.Success,
                    Data = account
                });
            }
            else
            {
                return(new Result <Account>()
                {
                    Code = ResultCodes.BadRequest,
                    Message = $"Den iparxei o pelatis me kodiko {customerId}."
                });
            }
        }
Пример #4
0
        public async Task <Result <Accounts> > RegisterAsync(int customerID, RegisterAccountOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AccountNumber))
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(options.AccountDescr))
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(options.Currency))
            {
                return(null);
            }

            var result = await _customer.GetCustomerbyIDAsync(customerID);

            if (result.Code != ResultCodes.Success)
            {
                return new Result <Accounts>()
                       {
                           Code    = result.Code,
                           Message = result.Message
                       }
            }
            ;
            //if (customer == null)
            //    return null;

            var account = new Accounts()
            {
                AccountDescription = options.AccountDescr,
                AccountNumber      = options.AccountNumber,
                Currency           = options.Currency,
            };

            result.Data.Accounts.Add(account);

            await _dBContext.SaveChangesAsync();

            return(new Result <Accounts>()
            {
                Code = result.Code,
                Message = $"New Account ID {account.AccountsId} added for Customer ID {customerID}",
                Data = account
            });
        }
Пример #5
0
        private static void RunAccountsService(string[] args)
        {
            if (args.Length == 1)
            {
                Console.WriteLine(Usage());
            }
            else
            {
                var _account = Scope.ServiceProvider.GetRequiredService <IAccountsService>();
                switch (args[1])
                {
                case "-a":
                    var options = new RegisterAccountOptions()
                    {
                        AccountNumber = args[2].Split(',')[0],
                        AccountDescr  = args[2].Split(',')[1],
                        Currency      = args[2].Split(',')[2]
                    };
                    _account.Register(int.Parse(args[2].Split(',')[3]), options);
                    break;

                case "-q":
                    var result = _account.GetAccountbyID(int.Parse(args[2]));
                    if (result.Code == ResultCodes.Success)
                    {
                        var account = result.Data;
                        Console.WriteLine(
                            $"Account ID: {account.AccountsId}\n" +
                            $"Account Number: {account.AccountNumber}\n" +
                            $"Account Description: {account.AccountDescription}\n" +
                            $"Account Balance: {account.Balance}\n" +
                            $"Account Currency: {account.Currency}\n" +
                            $"Created On: {account.AuditInfo.Created}\n" +
                            $"Account Active: {account.State}");
                    }
                    else
                    {
                        Console.WriteLine("Account ID not found !");
                    }
                    break;
                }
            }
        }
Пример #6
0
        public Result <Accounts> Register(int customerID, RegisterAccountOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AccountNumber))
            {
                return new Result <Accounts>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = "Account Number is invalid!"
                       }
            }
            ;

            if (string.IsNullOrWhiteSpace(options.AccountDescr))
            {
                return new Result <Accounts>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = "Account Description not set"
                       }
            }
            ;

            if (string.IsNullOrWhiteSpace(options.Currency))
            {
                return new Result <Accounts>()
                       {
                           Code    = ResultCodes.BadRequest,
                           Message = "Currency is invalid"
                       }
            }
            ;

            var result = _customer.GetCustomerbyID(customerID);

            if (result.Code != ResultCodes.Success)
            {
                return new Result <Accounts>()
                       {
                           Code    = result.Code,
                           Message = result.Message
                       }
            }
            ;

            var account = new Accounts()
            {
                AccountDescription = options.AccountDescr,
                AccountNumber      = options.AccountNumber,
                Currency           = options.Currency,
            };

            result.Data.Accounts.Add(account);

            _dBContext.SaveChanges();

            return(new Result <Accounts>()
            {
                Code = ResultCodes.Success,
                Data = account
            });
        }