예제 #1
0
        public static void AnalyzeUserCommand()
        {
            Person    person    = ObjectProvider.MakePersonInstance();
            PhoneBook phonebook = ObjectProvider.MakePhonebookInstance();
            Number    number    = ObjectProvider.MakeNumberInstance();

            switch (UserCommand)
            {
            case "Show All":
                ShowAllInfos();
                break;

            case "Person New":
                person.Add();
                break;

            case "Person Edit":
                person.FindPerson().UpdatePersonTotally();
                break;

            case "Person Delete":
                person.Delete();
                break;

            case "Person View Info":
                person.PrintPersonNumbers();
                break;

            case "PhoneBook New":
                phonebook.Add();
                break;

            case "PhoneBook Edit":
                phonebook.UpdatePhonebook();
                break;

            case "PhoneBook Delete":
                phonebook.Delete();
                break;

            case "Number New":
                number.Add();
                break;

            case "Number Edit":
                number.UpdateNumber();
                break;

            case "Number Delete":
                number.Delete();
                break;

            case "exit":
                Console.WriteLine("\n\t\tSee you later.");
                break;

            default:
                break;
            }
        }
예제 #2
0
        public PhoneBook FindPhonebook()
        {
            Console.Write("Enter phonebook's id: ");
            int id = int.Parse(Console.ReadLine());
            var db = ObjectProvider.MakeDbInstance();

            return(db.PhoneBooks.FirstOrDefault(x => x.Id == id));
        }
        public Number FindNumber()
        {
            Console.Write("Enter number's id: ");
            int id = int.Parse(Console.ReadLine());
            var db = ObjectProvider.MakeDbInstance();

            return(db.Numbers.FirstOrDefault(x => x.Id == id));
        }
        public int Add()
        {
            //var db = ObjectProvider.MakeDbInstance();

            Person aPerson = ObjectProvider.MakePersonInstanceWithFullDetails();

            db.Add(aPerson);
            db.SaveChanges();
            return(aPerson.Id);
        }
예제 #5
0
        public int Delete()
        {
            var db = ObjectProvider.MakeDbInstance();

            Console.Write("Enter phonebook's id: ");
            int id = int.Parse(Console.ReadLine());

            db.Remove(db.PhoneBooks.FirstOrDefault(x => x.Id == id));
            db.SaveChanges();
            return(id);
        }
예제 #6
0
        public int UpdatePhonebook()
        {
            PhoneBook foundPhonebook = FindPhonebook();

            Console.Write("Enter new phonebook title: ");
            foundPhonebook.Title = Console.ReadLine();
            var db = ObjectProvider.MakeDbInstance();

            db.Update(foundPhonebook);
            db.SaveChanges();
            return(foundPhonebook.Id);
        }
예제 #7
0
        public int Add()
        {
            var       db         = ObjectProvider.MakeDbInstance();
            PhoneBook aPhonebook = ObjectProvider.MakePhonebookInstance();

            Console.Write("Enter phonebook's title: ");
            aPhonebook.Title = Console.ReadLine();
            Console.Write("Enter the id of belonging person: ");
            aPhonebook.PhonebookPersonId = int.Parse(Console.ReadLine());
            db.Add(aPhonebook);
            db.SaveChanges();
            return(aPhonebook.Id);
        }
        public int UpdateNumber()
        {
            Number foundNumber = FindNumber();

            Console.Write("Enter new phone number: ");
            foundNumber.ContactValue = Console.ReadLine();
            Console.Write("Enter new title for the phone number: ");
            foundNumber.ContactTitle = Console.ReadLine();
            var db = ObjectProvider.MakeDbInstance();

            db.Update(foundNumber);
            db.SaveChanges();
            return(foundNumber.Id);
        }
        public int Add()
        {
            var    db      = ObjectProvider.MakeDbInstance();
            Number aNumber = ObjectProvider.MakeNumberInstance();

            Console.Write("Enter phone number: ");
            aNumber.ContactValue = Console.ReadLine();
            Console.Write("Enter a title for this phone number: ");
            aNumber.ContactTitle = Console.ReadLine();
            Console.Write("Enter the id of belonging phonebook: ");
            aNumber.PhonebookId = int.Parse(Console.ReadLine());
            db.Add(aNumber);
            db.SaveChanges();
            return(aNumber.Id);
        }
        public int UpdatePersonTotally()
        {
            Person foundedPerson = FindPerson();
            // ask client if it just needs some specific editions
            Person person = ObjectProvider.MakePersonInstanceWithFullDetails();

            foundedPerson.FirstName      = person.FirstName;
            foundedPerson.LastName       = person.LastName;
            foundedPerson.FatherName     = person.FatherName;
            foundedPerson.EmailAddress   = person.EmailAddress;
            foundedPerson.WebsiteAddress = person.WebsiteAddress;
            //var db = ObjectProvider.MakeDbInstance();
            db.Update(foundedPerson);
            db.SaveChanges();
            return(foundedPerson.Id);
        }
예제 #11
0
        public static void ShowAllInfos()
        {
            AppDbContext db = ObjectProvider.MakeDbInstance();

            db.Persons.ToList().ForEach(eachPerson =>
            {
                Console.WriteLine($"\tPerson id is : {eachPerson.Id}");
                var personPhonebooks = eachPerson.FindPhonebooksWithBelongingNumbers(eachPerson.Id);
                personPhonebooks.ToList().ForEach(phonebook =>
                {
                    Console.WriteLine($"\t\tphonebook id is : {phonebook.Id}");
                    phonebook.PhonebookNumbers.ToList().ForEach(number =>
                    {
                        Console.WriteLine($"\t\t\t{number.ContactTitle}  {number.ContactValue}");
                    });
                });
            });
        }