private static Tuple <List <PersonDetails>, List <PersonDetails> > _DivideList(List <PersonDetails> persons) { List <PersonDetails> sortedList = PersonDetails.SortPersons(persons); List <PersonDetails> personList = new List <PersonDetails>(); List <PersonDetails> petList = new List <PersonDetails>(); foreach (var item in sortedList) { if (item is Pet) { petList.Add(item); } else { personList.Add(item); } } return(new Tuple <List <PersonDetails>, List <PersonDetails> >(personList, petList)); }
public static void Main(string[] args) { List <PersonDetails> persons = new List <PersonDetails>(); do { Type = _Menu(); PersonDetails personObj = new PersonDetails(); Pet petObj = new Pet(); switch (Type) { case 1: var getPerson = _Get(); if (getPerson.Item2 != DateTime.MinValue) { persons.Add(new PersonDetails(getPerson.Item1, getPerson.Item2)); Console.WriteLine("\nDetails Added\n"); } else { Console.WriteLine("\nInvalid Date\n"); } break; case 2: var getPet = _Get(); string petBreed = _GetPetBreed(); if (getPet.Item2 != DateTime.MinValue) { persons.Add(new Pet(getPet.Item1, petBreed, getPet.Item2)); Console.WriteLine("\nDetails Added\n"); } else { Console.WriteLine("\nInvalid Date\n"); } break; case 3: if (persons.Count != 0) { List <PersonDetails> sortedList = PersonDetails.SortPersons(persons); Console.WriteLine("\nThe sorted list is :\n"); foreach (var item in sortedList) { _Output(item); } } else { Console.WriteLine("\nlist is empty\n"); } break; case 4: var lists = _DivideList(persons); if (lists.Item1.Count != 0) { personObj.Serializer(lists.Item1); } if (lists.Item2.Count != 0) { petObj.Serializer(lists.Item2); } Console.WriteLine("\nWritten to File\n"); break; case 5: if (File.Exists(@"D:/PersonDetails.json")) { if (new FileInfo(@"D:/PersonDetails.json").Length != 0) { personObj.Deserializer(); } else { Console.WriteLine("File is Empty"); } } if (File.Exists(@"D:/Pets.xml")) { if (new FileInfo(@"D:/Pets.xml").Length != 0) { petObj.Deserializer(); } else { Console.WriteLine("File is Empty"); } } break; case 6: var lists1 = _DivideList(persons); if (lists1.Item1.Count != 0) { personObj.Write(lists1.Item1); } if (lists1.Item2.Count != 0) { petObj.Write(lists1.Item2); } Console.WriteLine("\nDatabase Updated\n"); break; case 7: personObj.Read(); petObj.Read(); break; default: Console.WriteLine("Invalid Entry"); break; } Console.WriteLine("Do you wish to continue(y/n)?"); } while (Console.ReadLine() == "y"); Console.WriteLine("\nPress any key to exit"); Console.ReadLine(); }