Beispiel #1
0
        static void Main(string[] args)
        {
            var theBloodBank = new BloodBank();

            Console.WriteLine("Welcome to the ComIT Blood bank!");

            while (true)
            {
                Console.WriteLine("d - make donation; r - request donation; u - send update; q - quit");

                string userInput = Console.ReadLine();

                if (userInput == "d")
                {
                    theBloodBank.MakeDonation();
                }

                if (userInput == "r")
                {
                    theBloodBank.RequestDonation();
                }

                if (userInput == "u")
                {
                    theBloodBank.SendUpdateToAllMembers();
                }

                if (userInput == "q")
                {
                    break;
                }
            }

            Console.WriteLine("See you later!");
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var donorStorageSystem = new DonorStorageDB();
            // 3.3: Initialize the donationStorageSystem and inject it into the BloodBank constructor
            var theBloodBank = new BloodBank(donorStorageSystem);

            Console.WriteLine("Welcome to the ComIT Blood bank!");

            while (true)
            {
                Console.WriteLine("d - make donation; r - request donation; u - send update; p - print details; q - quit");

                string userInput = Console.ReadLine();

                if (userInput == "d")
                {
                    Console.WriteLine("Please enter the Donor ID:");
                    string donorId = Console.ReadLine();

                    try {
                        Guid donorIdGuid = Guid.Parse(donorId);
                        var  donation    = theBloodBank.MakeDonation(donorIdGuid);
                        Console.WriteLine($"Donation complete. ID: {donation.Id}");
                    }
                    catch (Exception e) {
                        // Handle the exception in here
                        Console.WriteLine($"Exception generated: {e.Message}");
                    }
                }

                if (userInput == "r")
                {
                    theBloodBank.RequestDonation();
                }

                if (userInput == "u")
                {
                    theBloodBank.SendUpdateToAllMembers();
                }

                if (userInput == "p")
                {
                    string memberDetails = theBloodBank.GetAllMemberDetails();
                    Console.WriteLine(memberDetails);
                }

                if (userInput == "q")
                {
                    break;
                }
            }

            Console.WriteLine("See you later!");
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // connect to the database

            var donorStorageSystem    = new DonorStorageList();
            var receiverStorageSystem = new ReceiverStorageList();
            var donationStorageSystem = new DonationStorageList();
            // 3.3: Initialize the donationStorageSystem and inject it into the BloodBank constructor
            var theBloodBank = new BloodBank(donorStorageSystem, donationStorageSystem, receiverStorageSystem);

            Console.WriteLine("Welcome to the ComIT Blood bank!");

            while (true)
            {
                Console.WriteLine("\nPlease select an option:\n" +
                                  "- d: make a donation\n" +
                                  "- r: request a donation\n" +
                                  "- a: list all donations\n" +
                                  "- m: list all members\n" +
                                  "- q: quit\n"
                                  );
                string userInput = Console.ReadLine();

                // MAKE DONATION
                if (userInput == "d")
                {
                    Console.WriteLine("Please enter the Donor ID:");
                    string donorId = Console.ReadLine();

                    try {
                        Guid donorIdGuid = Guid.Parse(donorId);
                        var  donation    = theBloodBank.MakeDonation(donorIdGuid);
                        Console.WriteLine($"Donation complete. ID: {donation.Id}");
                    }
                    catch (Exception e) {
                        Console.WriteLine($"Error: {e.Message}");
                    }
                }

                // REQUEST DONATION
                if (userInput == "r")
                {
                    Console.WriteLine("Please enter the Receiver ID:");
                    string receiverId = Console.ReadLine();

                    try {
                        Guid receiverIdGuid = Guid.Parse(receiverId);
                        bool success        = theBloodBank.RequestDonation(receiverIdGuid);

                        if (success)
                        {
                            Console.WriteLine($"Transaction successful");
                        }
                        else
                        {
                            Console.WriteLine($"No available donations at this time.");
                        }
                    }
                    catch (Exception e) {
                        Console.WriteLine($"Error: {e.Message}");
                    }
                }

                // VIEW ALL DONATIONS
                if (userInput == "a")
                {
                    try {
                        var donations = theBloodBank.GetDonations();
                        foreach (var donation in donations)
                        {
                            Console.WriteLine(donation.ToString());
                        }
                    } catch (Exception e) {
                        Console.WriteLine($"Error: {e.Message}");
                    }
                }

                // VIEW ALL MEMBERS
                if (userInput == "m")
                {
                    try {
                        var members = theBloodBank.GetMembers();
                        foreach (var member in members)
                        {
                            Console.WriteLine(member.ToString());
                        }
                    } catch (Exception e) {
                        Console.WriteLine($"Error: {e.Message}");
                    }
                }

                if (userInput == "q")
                {
                    break;
                }
            }

            Console.WriteLine("See you later!");
        }