285 Creating Customer PL - Add and List

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);
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄健华Yeah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值