public OverDraft FindActiveOverdraft(int accountHolderId)
        {
            List <OverDraft> allOverdraft    = FindMultipleOverdraftByAccountHolderId(accountHolderId);
            OverDraft        activeOverdraft = FindActiveOverdraft(allOverdraft);

            return(activeOverdraft);
        }
        public bool checkOverdraftBalance(int accountHolderId, bool printStatus = true)
        {
            List <OverDraft> allOverdrafts = FindMultipleOverdraftByAccountHolderId(accountHolderId);

            if (allOverdrafts == null)
            {
                return(false);
            }

            else
            {
                OverDraft activeOverdraft = FindActiveOverdraft(allOverdrafts);

                if (activeOverdraft == null)
                {
                    return(false);
                }
                else
                {
                    if (printStatus)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"You currently have unpaid overdraft of of {activeOverdraft.AmountLeft}");
                    }
                    return(true);
                }
            }
        }
        public void GetOverdraft(AccountHolder account, double amount)
        {
            int       id           = Overdrafts.Count() + 1;
            OverDraft newOverdraft = new OverDraft(id, account, amount);

            Overdrafts.Add(newOverdraft);
            RefreshFile();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"You have successfully gotten an overdraft of {amount}");
        }
        private static void RefreshFile()
        {
            TextWriter textWriter = new StreamWriter(OverdraftsFilePath);

            foreach (OverDraft overDraft in Overdrafts)
            {
                textWriter.WriteLine(OverDraft.ConvertToString(overDraft));
            }
            textWriter.Flush();
            textWriter.Close();
        }
        public void PayOverdraft(AccountHolder account, double amount)
        {
            // account.AccountBalance+=amount;
            OverDraft activeOverdraft = FindActiveOverdraft(account.Id);

            if (activeOverdraft != null)
            {
                activeOverdraft.AmountLeft -= amount;



                if (activeOverdraft.AmountLeft <= 0)
                {
                    activeOverdraft.AmountLeft = 0;
                    activeOverdraft.Status     = "inactive";
                }

                RefreshFile();
            }
        }
        public OverdraftManagement()
        {
            Overdrafts = new List <OverDraft>();

            try
            {
                if (!File.Exists(OverdraftsFilePath))
                {
                }
                else
                {
                    var lines = File.ReadAllLines(OverdraftsFilePath);
                    foreach (var line in lines)
                    {
                        var overdrafts = OverDraft.TextSplitter(line);
                        Overdrafts.Add(overdrafts);
                    }
                }
            }
            catch (IOException ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public static string ConvertToString(OverDraft overDraft)
 {
     return($"{overDraft.Id}\t{overDraft.AccountHolderId}\t{overDraft.Amount}\t{overDraft.OverdraftDate}\t{overDraft.Status}\t{overDraft.AmountLeft}");
 }
        public OverDraft FindActiveOverdraft(List <OverDraft> multipleOverdraft)
        {
            OverDraft activeOverdraft = multipleOverdraft.Find(i => i.Status == "active");

            return(activeOverdraft);
        }