CustomersPresentation.cs
using HJHBank.BussinessLayer.BALContracts;
using HJHBank.BussinessLayer;
using HJHBank.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HJHBank.Presentation
{
public static class CustomersPresentation
{
internal static void AddCustomer()
{
try
{
//create an object of Customer
Customer customer = new Customer();
//read all details from the user
Console.WriteLine("\n********ADD CUSTOMER*************");
Console.Write("Customer Name: ");
customer.CustomerName = Console.ReadLine();
Console.Write("Address: ");
customer.Address = Console.ReadLine();
Console.Write("Landmark: ");
customer.Landmark = Console.ReadLine();
Console.Write("City: ");
customer.City = Console.ReadLine();
Console.Write("Country: ");
customer.Country = Console.ReadLine();
Console.Write("Mobile: ");
customer.Mobile = Console.ReadLine();
//Create BL object
ICustomersBusinessLogicLayer customersBusinessLogicLayer = new CustomersBusinessLogicLayer();
Guid newGuid = customersBusinessLogicLayer.AddCustomer(customer);
List<Customer> matchingCustomers = customersBusinessLogicLayer.GetCustomersByCondition(item => item.CustomerID == newGuid);
if (matchingCustomers.Count >= 1)
{
Console.WriteLine("New Customer Code: " + matchingCustomers[0].CustomerCode);
Console.WriteLine("Customer Added.\n");
}
else
{
Console.WriteLine("Customer Not added");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.GetType());
}
}
internal static void ViewCustomers()
{
try
{
//Create BL object
ICustomersBusinessLogicLayer customersBusinessLogicLayer = new CustomersBusinessLogicLayer();
List<Customer> allCustomers = customersBusinessLogicLayer.GetCustomers();
Console.WriteLine("\n**********ALL CUSTOMERS*************");
//read all customers
foreach (var item in allCustomers)
{
Console.WriteLine("Customer Code: " + item.CustomerCode);
Console.WriteLine("Customer Name: " + item.CustomerName);
Console.WriteLine("Address: " + item.Address);
Console.WriteLine("Landmark: " + item.Landmark);
Console.WriteLine("City: " + item.City);
Console.WriteLine("Country: " + item.Country);
Console.WriteLine("Mobile: " + item.Mobile);
Console.WriteLine();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.GetType());
}
}
}
}
Program.cs
namespace HJHBank.Presentation
{
internal class Program
{
static void Main(string[] args)
{
//display title
System.Console.WriteLine("************** HJH Bank *****************");
System.Console.WriteLine("::Login Page::");
//declare variables to store username and password;
string userName = null, password = null;
//read userName from keyboard
System.Console.Write("Username: ");
userName = System.Console.ReadLine();
//read password from keyboard only if username is entered
if (userName != "")
{
System.Console.Write("Password: ");
password = System.Console.ReadLine();
}
//check username and password
if (userName == "system" && password == "manager")
{
//declare variable to store menu choice
int mainMenuChoice = -1;
do
{
//show main menu
System.Console.WriteLine("\n:::Main menu:::");
System.Console.WriteLine("1. Customers");
System.Console.WriteLine("2. Accounts");
System.Console.WriteLine("3. Funds Transfer");
System.Console.WriteLine("4. Funds Transfer Statement");
System.Console.WriteLine("5. Account Statement");
System.Console.WriteLine("0. Exit");
//accept menu choice from keyboard
System.Console.Write("Enter choice: ");
mainMenuChoice = int.Parse(System.Console.ReadLine());
//switch-case to check menu choice
switch (mainMenuChoice)
{
case 1: CustomersMenu(); break;
case 2: AccountsMenu(); break;
case 3: //TO DO: Display funds transfer menu
break;
case 4: //TO DO: Display funds transfer statement menu
break;
case 5: //TO DO: Display account statement menu
break;
}
} while (mainMenuChoice != 0);
}
else
{
System.Console.WriteLine("Invalid username or password");
}
//about to exit
System.Console.WriteLine("Thank you! Visit again.");
System.Console.ReadKey();
}
static void CustomersMenu()
{
//variable to store customers menu choice
int customerMenuChoice = -1;
//do-while loop starts
do
{
//print customers menu
System.Console.WriteLine("\n:::Customers menu:::");
System.Console.WriteLine("1. Add Customer");
System.Console.WriteLine("2. Delete Customer");
System.Console.WriteLine("3. Update Customer");
System.Console.WriteLine("4. Search Customers");
System.Console.WriteLine("5. View Customers");
System.Console.WriteLine("0. Back to Main Menu");
//accept customers menu choice
System.Console.Write("Enter choice: ");
customerMenuChoice = System.Convert.ToInt32(System.Console.ReadLine());
//switch case
switch (customerMenuChoice)
{
case 1: CustomersPresentation.AddCustomer(); break;
case 5: CustomersPresentation.ViewCustomers(); break;
}
} while (customerMenuChoice != 0);
}
static void AccountsMenu()
{
//variable to store accounts menu choice
int accountsMenuChoice = -1;
//do-while loop starts
do
{
//print accounts menu
System.Console.WriteLine("\n:::Accounts menu:::");
System.Console.WriteLine("1. Add Account");
System.Console.WriteLine("2. Delete Account");
System.Console.WriteLine("3. Update Account");
System.Console.WriteLine("4. View Accounts");
System.Console.WriteLine("0. Back to Main Menu");
//accept accounts menu choice
System.Console.Write("Enter choice: ");
accountsMenuChoice = System.Convert.ToInt32(System.Console.ReadLine());
} while (accountsMenuChoice != 0);
}
}
}