Exemple #1
0
        /// <summary>
        /// Raderar person
        /// </summary>
        private void DeletePerson()
        {
            Console.Clear();
            Utilitys.LogoDelete();
            var list = new List <Person>();
            var db   = new SQLDatabase();

            Utilitys.PrintGreen("Enter name on person you wanna delete: ");
            var name    = Console.ReadLine();
            var persons = db.GetPersons(name);

            if (persons.Count > 0)
            {
                var ctr = 1;
                foreach (var person in persons)
                {
                    var info = $"{ctr++}. {person.FirstName} {person.LastName} Born: {person.Born}";
                    Console.WriteLine(info);
                }
                Console.WriteLine("0. None of the above");
                var option = ChoosePerson(persons.Count);
                try
                {
                    var member = (persons[option - 1]);
                    var dt     = db.ShowAllFrom();
                    foreach (DataRow row in dt.Rows)
                    {
                        list.Add(db.GetPerson(row));
                    }
                    foreach (var members in list)
                    {
                        if (members.Mother == member.Id)
                        {
                            members.Mother = 0;
                            db.Update(members);
                        }
                        else if (members.Father == member.Id)
                        {
                            members.Father = 0;
                            db.Update(members);
                        }
                        else
                        {
                            db.Delete(member.Id);
                        }
                    }
                    Utilitys.PrintGreen($"{member.FirstName} Was succesfully deleted!");
                }
                catch
                {
                    Utilitys.PrintRed("Wrong input!");
                }
            }
            else
            {
                Utilitys.PrintRed($"{name} was not found in the DB");
            }
            Console.WriteLine("[Press any key to go back]");
            Console.ReadKey();
        }
Exemple #2
0
        /// <summary>
        /// Ascii art logo för Addperson
        /// </summary>
        public static void LogoAddPerson()
        {
            Utilitys.PrintGreen(@"
    ___       __    __
   /   | ____/ /___/ /  ____  ___  ______________  ____
  / /| |/ __  / __  /  / __ \/ _ \/ ___/ ___/ __ \/ __ \
 / ___ / /_/ / /_/ /  / /_/ /  __/ /  (__  ) /_/ / / / /
/_/  |_\__,_/\__,_/  / .___/\___/_/  /____/\____/_/ /_/
                    /_/

");
        }
Exemple #3
0
        /// <summary>
        /// Lägger till Personer till Databasen
        /// </summary>
        private void AddPerson()
        {
            Console.Clear();
            Utilitys.LogoAddPerson();
            var db     = new SQLDatabase();
            var person = new Person();

            try
            {
                Console.Write("[Required]\nEnter first name: ");
                person.FirstName = Console.ReadLine();
                Console.Write("[Required]\nEnter last name: ");
                person.LastName = Console.ReadLine();
                Console.Write("[Optional]\nEnter year of birth-(yyyy): ");
                person.Born = int.Parse(Console.ReadLine());
            }
            catch
            {
                Debug.Write("Wrong input");
            }

            if (person.FirstName?.Length == 0 || person.LastName?.Length == 0)
            {
                Utilitys.PrintRed("Worng input, try again? (y/n)");
                var choice = Console.ReadLine();
                if (string.Equals(choice, "y", StringComparison.OrdinalIgnoreCase))
                {
                    AddPerson();
                }
            }
            else
            {
                person = db.CreatePerson(person);
                Utilitys.PrintGreen($"{person.FirstName} was added");
            }
            Console.WriteLine("Press any key to go back!");
            Console.ReadKey();
        }