Answer to Question #274129 in C# for deep

Question #274129

Create simple basic structure for class object and relation using Class Library and Console Application Project of BloodInventory: BloodInventoryID, BloodGroup, NumberofBottles, BloodBankID, ExpiryDate where a. User will be able to view the blood available in all blood banks b. User can transfer blood from one bank to another bank or hospital as per that updation in the quantity should happen c. Delete the blood details if it is expired 


1
Expert's answer
2021-12-01T18:38:11-0500
class BloodInventory
    {
        public int BloodInventoryID { get; set; }
        public int BloodGroup { get; set; }
        public int NumberofBottles { get; set; }
        public int BloodBankID { get; set; }
        public DateTime ExpiryDate { get; set; }


        public BloodInventory(int BloodInventoryID, int BloodGroup, int NumberofBottles, int BloodBankID, DateTime ExpiryDate)
        {
            this.BloodInventoryID = BloodInventoryID;
            this.BloodGroup = BloodGroup;
            this.NumberofBottles = NumberofBottles;
            this.ExpiryDate = ExpiryDate;
            this.BloodBankID = BloodBankID;
        }


        public override string ToString()
        {
            return $"BloodInventoryID: {BloodInventoryID}, BloodGroup: {BloodGroup}, NumberofBottles: {NumberofBottles},BloodBankID: {BloodBankID}, ExpiryDate: {ExpiryDate.ToString()}";
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            List<BloodInventory> bloodInventories = new List<BloodInventory>()
            {
                new BloodInventory(0,1,10,0,new DateTime(2025,10,10)),
                new BloodInventory(1,1,15,1,new DateTime(2025,10,10)),
                new BloodInventory(2,2,20,2,new DateTime(2025,10,10)),
                new BloodInventory(3,3,10,3,new DateTime(2025,10,10)),
                new BloodInventory(4,1,13,4,new DateTime(2020,10,10)),
            };
            bool flag = true;
            while (flag)
            {
                Console.WriteLine("1.View the blood available in all blood banks \n2.Move blood from one bank to another \n3.Delete the blood details if it is expired");
                switch (Console.ReadLine())
                {
                    case "1":
                        {
                            Display(bloodInventories);
                            break;
                        }
                    case "2":
                        {
                            Console.WriteLine("Enter which blood bank from which you want to transfer blood and in what quantity");
                            Console.Write("From this bank you will transport blood:");
                            int FromtransferbankID = int.Parse(Console.ReadLine());
                            Console.Write("You will transfer blood to this bank: ");
                            int TotransferbankID = int.Parse(Console.ReadLine());
                            Console.Write("Number of bottles of blood transported: ");
                            int bottleofblood = int.Parse(Console.ReadLine());
                            BloodInventory fromtest = bloodInventories.FirstOrDefault(b => b.BloodBankID == FromtransferbankID);
                            if (fromtest == null)
                            {
                                Console.WriteLine("Erroor");
                                break;
                            }
                                
                            BloodInventory toTest = bloodInventories.FirstOrDefault(b => b.BloodBankID == TotransferbankID);
                            if (toTest == null)
                            {
                                Console.WriteLine("Erroor");
                                break;                                
                            }
                            if (fromtest.BloodGroup == toTest.BloodGroup)
                            {
                                toTest.NumberofBottles += bottleofblood;
                            }
                            else
                                bloodInventories.Add(new BloodInventory(fromtest.BloodInventoryID, fromtest.BloodGroup, bottleofblood, toTest.BloodBankID, fromtest.ExpiryDate));
                            fromtest.NumberofBottles -= bottleofblood;
                            break;
                        }
                    case "3":
                        {
                            DeleteToExpiryDate(bloodInventories);
                            break;
                        }
                    default:
                        {
                            flag = false;
                            break;
                        }
                }
            }
        }
        public static void Display(List<BloodInventory> bloodInventories)
        {
            foreach (var item in bloodInventories)
            {
                Console.WriteLine(item);
            }
        }
        public static void DeleteToExpiryDate(List<BloodInventory> bloodInventories)
        {
            for (int i = 0; i < bloodInventories.Count; i++)
            {
                if (bloodInventories[i].ExpiryDate < DateTime.Now)
                {
                    bloodInventories.Remove(bloodInventories[i]);
                    i = 0;
                }
            }
        }


    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS