public void GivenVetIdListPetsAndOwnners(VeterinaryModelContainer db) { int vetId = Int32.Parse(getVetId()); bool vetIdExists = db.Vets.Any(r => r.Id.Equals(vetId)); if (vetIdExists) { var query = from v in db.Vets join vi in db.Visits on v.Id equals vi.VetId join p in db.Pets on vi.PetId equals p.Id join o in db.Owners on p.OwnerId equals o.Id where v.Id.Equals(vetId) orderby vi.VisitDate descending select new { vets = v, visits = vi, pets = p, owners = o }; if (query.Any()) { string date = getDate(); DateTime dateTimeInputed = Convert.ToDateTime(date); Console.WriteLine("Appointments for Vet " + query.FirstOrDefault().vets.Firstname + " " + query.FirstOrDefault().vets.Surname + " on date " + date); bool noAppointments = false; foreach (var item in query) { DateTime dateTime = Convert.ToDateTime(item.visits.VisitDate); if (dateTimeInputed.Equals(dateTime)) { Console.WriteLine("DETAILS OF VISIT" + "\n---------------"); Console.WriteLine("Name of Pet: " + item.pets.Name); Console.WriteLine("Name of Owner: " + item.owners.Firstname + " " + item.owners.Surname); } else { noAppointments = true; } } if (noAppointments) { Console.WriteLine("NO APPOINTMENTS ON THIS DATE"); } Console.WriteLine("---------------------------------------"); } else { Console.WriteLine("THIS VET DOES NOT HAVE ANY APPOINTMENTS YET"); } } else { Console.WriteLine("THAT VETID DOES NOT EXIST IN THE RECORDS"); Console.WriteLine("---------------------------------------"); } }
public void GivenPetIdCalculateInvoice(VeterinaryModelContainer db) { int petId = Int32.Parse(getPetId()); bool petIdExists = db.Pets.Any(r => r.Id.Equals(petId)); if (petIdExists) { decimal labourRate = 40; var query = from vi in db.Visits join p in db.Pets on vi.PetId equals p.Id join m in db.Medications on vi.Id equals m.VisitId where vi.PetId.Equals(petId) orderby vi.VisitDate descending select new { visits = vi, pets = p, medication = m }; if (query.Any()) { Console.WriteLine("DETAILS OF VISIT"); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine(query.FirstOrDefault().pets.Name + " Last visited on " + query.FirstOrDefault().visits.VisitDate); Console.WriteLine("---------------------------------"); decimal totalMedicationCost = 0; foreach (var item in query) { if (query.FirstOrDefault().visits.Id.Equals(item.medication.VisitId)) { decimal medicationPrice = decimal.Parse(item.medication.MedicationPrice); int medicationQty = Int32.Parse(item.medication.MedicationQty); decimal medicationCost = medicationPrice * medicationQty; totalMedicationCost += medicationCost; Console.WriteLine("Medication Issued: " + item.medication.MedicationName); Console.WriteLine("Medication Price: £" + medicationPrice); Console.WriteLine("Medication Qty: " + item.medication.MedicationQty); Console.WriteLine("---------------------------------"); } } Console.WriteLine("Total Medication Cost: £" + totalMedicationCost); Console.WriteLine("Labour Time: " + query.FirstOrDefault().visits.DurationHours + "hrs"); Console.WriteLine("Labour Cost: £" + labourRate); Console.WriteLine("Total Cost: £" + (labourRate + totalMedicationCost)); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++"); } else { Console.WriteLine("NO VISITS IN RECORDS"); } } else { Console.WriteLine("PETID DOES NOT EXIST"); } }
public void ListPetAndVisitGivenPetId(VeterinaryModelContainer db) { int petId = Int32.Parse(getPetId()); bool petIdExists = db.Pets.Any(r => r.Id.Equals(petId)); if (petIdExists) { var query = from p in db.Pets join v in db.Visits on p.Id equals v.PetId where p.Id.Equals(petId) orderby v.VisitDate descending select new { pets = p, visits = v }; if (query.Any()) { Console.WriteLine("DETAILS OF PET WITH PETID " + petId); Console.WriteLine("Name: " + query.FirstOrDefault().pets.Name + "\nType: " + query.FirstOrDefault().pets.Type + "\nBreed: " + query.FirstOrDefault().pets.Breed); foreach (var item in query) { Console.WriteLine("DETIALS OF VISIT" + "\n---------------"); Console.WriteLine("Visit Date: " + item.visits.VisitDate + "\nVisit Reason: " + item.visits.VisitReason + "\n"); } Console.WriteLine("---------------------------------------"); } else { Console.WriteLine("ERROR WITH QUERY"); } } else { Console.WriteLine("THAT PETID DOES NOT EXIST IN THE RECORDS"); Console.WriteLine("---------------------------------------"); } }
//Given Practice RegNum list details of practice including vets who work there public void VetsGivenPracticeRegNum(VeterinaryModelContainer db) { string regNumber = getRegNumber(); bool regNumExists = db.Practices.Any(r => r.RegNumber.Equals(regNumber)); if (regNumExists) { var queryPracticeDetails = from p in db.Practices join v in db.Vets on p.Id equals v.PracticeId where p.RegNumber.Equals(regNumber) select new { practice = p, vetDetails = v }; if (queryPracticeDetails.Any()) { Console.WriteLine("DETAILS OF PRACTICE WITH REGNUM " + regNumber); Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); Console.WriteLine(queryPracticeDetails.FirstOrDefault().practice.PracticeName + " - " + queryPracticeDetails.FirstOrDefault().practice.Address + "\nVETS WORKING AT THIS PRACTICE:"); foreach (var item in queryPracticeDetails) { Console.WriteLine(item.vetDetails.Firstname + " " + item.vetDetails.Surname); } Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); } else { Console.WriteLine("ERROR WITH QUERY"); } } else { Console.WriteLine("THAT REGNUM DOES NOT EXIST IN THE RECORDS"); Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); } }
//List all Owners that are registered to the practice public void OwnersListing(VeterinaryModelContainer db) { var query = from o in db.Owners orderby o.Surname select o; if (query.Any()) { Console.WriteLine("VETERINARY PET OWNERS LISTING"); Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); foreach (var item in query) { Console.WriteLine(item.Surname + " " + item.Firstname); Console.WriteLine("Address: " + item.Address + "\nPhone Number: " + item.PhoneNumber); Console.WriteLine("---------------------------------------"); } Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); } else { Console.WriteLine("ERROR WITH QUERY"); } }
//List all pets registered to the practice public void PetListing(VeterinaryModelContainer db) { var query = from p in db.Pets orderby p.Name select p; if (query.Any()) { Console.WriteLine("VETERINARY PETS LISTING"); Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); foreach (var item in query) { Console.WriteLine("Name: " + item.Name + "\nType: " + item.Type + "\nBreed: " + item.Breed + "\n"); Console.WriteLine("---------------------------------------"); } Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); } else { Console.WriteLine("ERROR WITH QUERY"); } }
static void Main(string[] args) { VeterinaryMenu veterinaryMenu = new VeterinaryMenu(); using (var db = new VeterinaryModelContainer()) { Console.WriteLine("VETERNINARY PRACTICE ADMIN SYSTEM"); while (true) { Console.Write("(1) - List the Owners registered in the Veterinary Practice \n" + "(2) - List all the Pets registered in the Veterinary Practice \n" + "(3) - Given the practice RegNum display details of practice and all vets working there \n" + "(4) - Given a PetId, list Name, Type and Breed of Pet followed by date and reason of all visits \n" + "(5) - Given a VetId and a specified date, list all visits with that vet \n" + "(6) - Given a PetId, calculate the cost of the most recent visit to the vet \n" + "(7) - LOGOUT \n"); //Handle User selection int sel = 0; Console.WriteLine("ENTER Your Selection: "); while (!(int.TryParse(Console.ReadLine(), out sel) && (sel >= 1 && sel <= 7))) { Console.WriteLine("You need to enter a value between 1-7!"); Console.WriteLine("ENTER Your Selection: "); } Console.WriteLine(); switch (sel) { case 1: veterinaryMenu.OwnersListing(db); break; case 2: veterinaryMenu.PetListing(db); break; case 3: veterinaryMenu.VetsGivenPracticeRegNum(db); break; case 4: veterinaryMenu.ListPetAndVisitGivenPetId(db); break; case 5: veterinaryMenu.GivenVetIdListPetsAndOwnners(db); break; case 6: veterinaryMenu.GivenPetIdCalculateInvoice(db); break; case 7: Console.WriteLine("LOGGING OUT"); Environment.Exit(0); break; default: Console.WriteLine("Invalid selection"); break; } } } }