static void Main(string[] args) { bool exit = false; List <Bet> bets = new List <Bet>(); while (!exit) { Console.WriteLine("\n\n\tWelcome to the betting app, \nPress 1 to access the historical bets which are stored in a text file."); Console.WriteLine("Press 2 to write the bets you are currently working with to a binary file."); Console.WriteLine("Press 3 to read out all bets saved in the binary file \n\n(N.B. You will will erase data you are currently working with if you have not written it to the binary file)\n"); Console.WriteLine("Press 4 to add a bet. (You will need to write it to the binary file yourself)."); Console.WriteLine("Press 5 for a report that lists years, total won and total lost."); Console.WriteLine("Press 6 for a report that shows the most popular race course for bets."); Console.WriteLine("Press 7 for a report that shows the bets in date order."); Console.WriteLine("Press 8 for a report that displays the highest amount won for a bet laid and the most lost for a bet laid."); Console.WriteLine("Press 9 for a report to indicate how successful HotTipster is at horse betting."); Console.WriteLine("Press 0 to exit\n"); int selection; if (int.TryParse(Console.ReadLine(), out selection)) { switch (selection) { case 1: try { bets = GetHistoricalBets(); foreach (Bet bet in bets) { Console.WriteLine(bet.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 2: try { bets = CheckPresenceOfBets(bets); BinaryWriterMethod(bets); Console.WriteLine("Bets are successfully written to the binary file!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 3: try { bets = BinaryReaderMethod(); bets = CheckPresenceOfBets(bets); foreach (Bet bet in bets) { Console.WriteLine(bet.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 4: try { Bet newbet = BetAdder(); bets.Add(newbet); Console.WriteLine("Bet added successfully!"); } catch (SystemException) { Console.WriteLine("Wrong data entered!"); } break; case 5: try { bets = CheckPresenceOfBets(bets); ListTotalByYear(bets); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 6: try { bets = CheckPresenceOfBets(bets); ShowMostPopular(bets);; } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 7: try { bets = CheckPresenceOfBets(bets); ShowInOrderOfDate(bets); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 8: try { bets = CheckPresenceOfBets(bets); ShowHighestAndLowest(bets); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 9: try { bets = CheckPresenceOfBets(bets); ShowSuccess(bets); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case 0: exit = true; break; default: Console.WriteLine("Invalid selection"); break; } } } }
public static Bet GetHighestBetLost(List <Bet> bets) { Bet maxBetLost = bets.OrderByDescending(bet => bet.Amount).Where(bet => bet.Won == false).First(); return(maxBetLost); }