Ejemplo n.º 1
0
        public override async Task ExecuteAsync()
        {
            RenderTitle();
            Console.CursorVisible = true;

            var viewBalanceMsg = await Context.HttpClient.GetAsync(new Uri(Context.ApiUri, "account/balance"));

            if (viewBalanceMsg.IsSuccessStatusCode)
            {
                var balanceInfo = await viewBalanceMsg.Content.ReadAsAsync <BalanceInfo>();

                OutputHelpers.Notify($"Your balance is: {balanceInfo.Balance}");
            }
            else if (viewBalanceMsg.StatusCode == HttpStatusCode.Unauthorized)
            {
                OutputHelpers.Notify("Your session has timed out.");
                await Context.RemoveTokenAsync();

                return;
            }
            else
            {
                OutputHelpers.Notify("Error: Unknown. Please try again later.");
            }

            if (Context.CommandStack.Count > 0)
            {
                await Context.CommandStack.Pop().ExecuteAsync();
            }
        }
Ejemplo n.º 2
0
        public override async Task ExecuteAsync()
        {
            RenderTitle();
            Console.CursorVisible = true;

            var amount = InputHelpers.InputMoney("Amount to Deposit: ");

            var depositMsg = await Context.HttpClient.PostAsJsonAsync(new Uri(Context.ApiUri, "transaction/deposit"), new { amount });

            Console.WriteLine();

            if (depositMsg.IsSuccessStatusCode)
            {
                OutputHelpers.Notify($"You has successfully deposited {amount} into your account.");
            }
            else if (depositMsg.StatusCode == HttpStatusCode.Unauthorized)
            {
                OutputHelpers.Notify("Your session has timed out.");
                await Context.RemoveTokenAsync();

                return;
            }
            else
            {
                OutputHelpers.Notify("Error: Unknown. Please try again later.");
            }

            if (Context.CommandStack.Count > 0)
            {
                await Context.CommandStack.Pop().ExecuteAsync();
            }
        }
Ejemplo n.º 3
0
		public override async Task ExecuteAsync()
		{
			RenderTitle();
			Console.CursorVisible = true;

			var username = InputHelpers.InputNonEmptyString("Username: "******"First Name: ");
			var lastName = InputHelpers.InputString("Last Name: ");
			var password = "******";
			var confirmPassword = "******";

			while (password != confirmPassword || password.Trim().Length < 3)
			{
				password = InputHelpers.InputPassword("Password: "******"Confirm Password: "******"Error: Password and Confirmation Password are mismatched.");
					Console.WriteLine();
				}

				if (password.Trim().Length < 3)
				{
					Console.WriteLine();
					Console.WriteLine("Error: Password must contain at least 3 characters.");
					Console.WriteLine();
				}
			}

			var signUpMsg = await Context.HttpClient.PostAsJsonAsync(new Uri(Context.ApiUri, "account/signup"), new { username, firstName, lastName, password });

			Console.WriteLine();

			if (signUpMsg.StatusCode == HttpStatusCode.BadRequest)
			{
				OutputHelpers.Notify("Error: Username is registered.");
			}
			else if (signUpMsg.IsSuccessStatusCode)
			{
				OutputHelpers.Notify("Your account has been created.");
			}
			else
			{
				OutputHelpers.Notify("Error: Unknown. Please try again later.");
			}

			if (Context.CommandStack.Count > 0)
				await Context.CommandStack.Pop().ExecuteAsync();
		}
Ejemplo n.º 4
0
        public override async Task ExecuteAsync()
        {
            RenderTitle();
            Console.CursorVisible = true;

            var frm = InputHelpers.InputDateTime("From (e.g., Jan 1, 2019 1:05:30am): ");
            var to  = InputHelpers.InputDateTime("To (e.g., Jan 31, 2019 11:55:55pm): ");

            var viewTransactionsMsg = await Context.HttpClient.GetAsync(new Uri(Context.ApiUri, $"transaction/transactions?from={frm}&to={to}"));

            if (viewTransactionsMsg.IsSuccessStatusCode)
            {
                var transactionHistoryInfo = await viewTransactionsMsg.Content.ReadAsAsync <TransactionHistoryInfo>();

                Console.WriteLine();
                Console.WriteLine(transactionHistoryInfo.Transactions.Count() > 0
                                        ? "Transactions:"
                                        : "You don't have any transactions in this period.");

                foreach (var tran in transactionHistoryInfo.Transactions)
                {
                    Console.Write($"{tran.DateTime.ToLocalTime().ToString()}: {(tran.Amount > 0 ? "Deposit " : "Withdraw")} {Math.Abs(tran.Amount)}");
                    Console.WriteLine();
                }

                Console.ReadKey();
            }
            else if (viewTransactionsMsg.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                OutputHelpers.Notify("Your session has timed out.");
                await Context.RemoveTokenAsync();
            }
            else
            {
                OutputHelpers.Notify("Error: Unknown. Please try again later.");
            }

            if (Context.CommandStack.Count > 0)
            {
                await Context.CommandStack.Pop().ExecuteAsync();
            }
        }
Ejemplo n.º 5
0
        static async Task Main(string[] args)
        {
            var apiUrl = new Uri(ConfigurationManager.AppSettings.Get("BankingLedgerApiUrl"));

            using (var context = new Context(apiUrl))
            {
                context.OnAuthenticated   += async(sender, e) => await new AuthenticatedScreen(context).ExecuteAsync();
                context.OnUnauthenticated += async(sender, e) => await new UnauthenticatedScreen(context).ExecuteAsync();

                try
                {
                    await context.StartAsync();
                }
                catch (HttpRequestException)
                {
                    Console.WriteLine();
                    OutputHelpers.Notify("Cannot connect to Banking Ledger API Server. Please try again later.");
                    await context.RemoveTokenAsync();
                }
            }
        }
Ejemplo n.º 6
0
        public override async Task ExecuteAsync()
        {
            RenderTitle();
            Console.CursorVisible = true;

            var username = InputHelpers.InputNonEmptyString("Username: "******"Password: "******"account/signin"), new { username, password });

            Console.WriteLine();

            if (signInMsg.StatusCode == HttpStatusCode.Unauthorized)
            {
                OutputHelpers.Notify("Error: Username or password are incorrect.");

                if (Context.CommandStack.Count > 0)
                {
                    await Context.CommandStack.Pop().ExecuteAsync();
                }
            }
            else if (signInMsg.IsSuccessStatusCode)
            {
                var tokenInfo = await signInMsg.Content.ReadAsAsync <TokenInfo>();

                await Context.SetTokenAsync(tokenInfo.Token);
            }
            else
            {
                OutputHelpers.Notify("Error: Unknown. Please try again later.");

                if (Context.CommandStack.Count > 0)
                {
                    await Context.CommandStack.Pop().ExecuteAsync();
                }
            }
        }
Ejemplo n.º 7
0
        public override async Task ExecuteAsync()
        {
            RenderTitle();
            Console.CursorVisible = true;

            var amount = InputHelpers.InputMoney("Amount to Withdraw: ");

            var withdrawMsg = await Context.HttpClient.PostAsJsonAsync(new Uri(Context.ApiUri, "transaction/withdraw"), new { amount });

            Console.WriteLine();

            if (withdrawMsg.IsSuccessStatusCode)
            {
                OutputHelpers.Notify($"You has successfully withdrawed {amount} from your account.");
            }
            else if (withdrawMsg.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                OutputHelpers.Notify("Your session has timed out.");
                await Context.RemoveTokenAsync();

                return;
            }
            else if (withdrawMsg.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                OutputHelpers.Notify($"Error: Your withdrawal amount is invalid.");
            }
            else
            {
                OutputHelpers.Notify("Error: Unknown. Please try again later.");
            }

            if (Context.CommandStack.Count > 0)
            {
                await Context.CommandStack.Pop().ExecuteAsync();
            }
        }