Exemple #1
0
        static void StudentChioce()
        {
            IStudentReposytory studentReposytory = Factories.GetFactory().GetStudentReposytory();
            string             key;

            do
            {
                Console.WriteLine("What do u want to do? Get all students?(all). Add student?(add). Update student?(update). Delete?(del). To back enter (b)");
                key = Console.ReadLine();
                try
                {
                    if (key == "all")
                    {
                        Console.WriteLine("There are such students: ");
                        Console.WriteLine();
                        foreach (var students in studentReposytory.GetAllStudents())
                        {
                            Console.WriteLine(string.Format("ID: {0}, First name: {1}, Last name: {2}, Birth: {3}, Academic group: {4}",
                                                            students.Id, students.FirstName, students.LastName, students.Birth, students.Group_number));
                        }
                        Console.WriteLine();
                    }
                    else if (key == "add")
                    {
                        Console.WriteLine("Enter id for new student: ");
                        int ID_for_new_elem = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter first name for new student: ");
                        string Name_for_new_student = Console.ReadLine();
                        Console.WriteLine("Enter last name for new student: ");
                        string Last_name_for_student = Console.ReadLine();
                        Console.WriteLine("enter new date of birth: ");
                        DateTime Date_of_birth = Convert.ToDateTime(Console.ReadLine());
                        Console.WriteLine("enter academic group: ");
                        int Academic_group = int.Parse(Console.ReadLine());
                        studentReposytory.Add(new Student
                        {
                            Id           = ID_for_new_elem,
                            FirstName    = Name_for_new_student,
                            LastName     = Last_name_for_student,
                            Birth        = Date_of_birth,
                            Group_number = Academic_group
                        });
                    }
                    else if (key == "update")
                    {
                        Console.WriteLine("Enter id of student u want to update: ");
                        int IdForUpdating = int.Parse(Console.ReadLine());
                        Console.WriteLine("enter new name: ");
                        string NameForUpdating = Console.ReadLine();
                        Console.WriteLine("enter new last name: ");
                        string LastNameForUpdate = Console.ReadLine();
                        Console.WriteLine("enter new date of birth: ");
                        DateTime Date_of_birth = Convert.ToDateTime(Console.ReadLine());
                        Console.WriteLine("enter new academic group: ");
                        int Academic_group = int.Parse(Console.ReadLine());
                        studentReposytory.Update(new Models.Student
                        {
                            Id           = IdForUpdating,
                            FirstName    = NameForUpdating,
                            LastName     = LastNameForUpdate,
                            Birth        = Date_of_birth,
                            Group_number = Academic_group
                        });
                    }
                    else if (key == "del")
                    {
                        Console.WriteLine("Enter id of student u want to delete: ");
                        int x = int.Parse(Console.ReadLine());
                        studentReposytory.Delete(new Models.Student
                        {
                            Id = x
                        });
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                Console.WriteLine("-------------------------------");
            } while (key != "b");
        }