Exemplo n.º 1
0
        public void TestInit()
        {
            TestStudentRepository = new Repository <Student>();
            TestSubjectRepository = new Repository <Subject>();
            TestGroupRepository   = new Repository <ISGroup>();

            //Students test init;
            for (int i = 0; i < 30; i++)
            {
                Student std = new Student(i);
                std.Name        = "Test" + i;
                std.Surname     = "Student" + i;
                std.MobilePhone = "+3809312345" + i;
                TestStudentRepository.Add(std);
            }

            for (int i = 0; i < 3; i++)
            {
                ISGroup group = new ISGroup(i, 110 + i);
                for (int k = i * 10; k < 10 * (i + 1); k++)
                {
                    group.AddStudent(k);
                }

                for (int j = 0; j < 5; j++)
                {
                    Subject subj    = new Subject(i * 10 + j);
                    Teacher teacher = new Teacher(i * 10 + j);
                    teacher.Name    = "Name" + i;
                    teacher.Surname = "Surname" + j;
                    subj.SetTeacher(teacher.Id);
                    subj.AddGroup(group.Id);
                    group.AddTeacher(teacher.Id);
                    TestSubjectRepository.Add(subj);
                }
                TestGroupRepository.Add(group);
            }

            TestSearchController = new SearchController(TestStudentRepository,
                                                        TestGroupRepository, TestSubjectRepository);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add group to repository
        /// </summary>
        /// <param name="newGroup">Group that will be added to repository</param>
        public void AddGroup(ISGroup newGroup)
        {
            var queryNumOfIds     = 0;
            var queryNumOfNumbers = 0;

            if (DataRepo.Count != 0)
            {
                queryNumOfIds     = DataRepo.Where(group => group.Id == newGroup.Id).Count();
                queryNumOfNumbers = DataRepo.Where(group =>
                                                   group.Number == newGroup.Number).Count();
            }
            if (queryNumOfIds == 0 && queryNumOfNumbers == 0)
            {
                DataRepo.Add(newGroup);
            }
            else
            {
                var errorMessage = "Group with " + newGroup.Id + " id, is already exist!";
                throw new Exception(errorMessage);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor with params where files loads
        /// </summary>
        /// <param inputString="Path">path to folder where will storage files</param>
        public View(String path)
        {
            Path = path;

            Thread StudentThread = new Thread(() =>
            {
                StudentRepository = new Repository <Student>(Path + "Students.cdat");
                StudentRepository.Load();
            });

            Thread GroupThread = new Thread(() =>
            {
                GroupRepository = new Repository <ISGroup>(Path + "Groups.cdat");
                GroupRepository.Load();
            });

            Thread SubjectThread = new Thread(() =>
            {
                SubjectRepository = new Repository <Subject>(Path + "Subject.cdat");
                SubjectRepository.Load();
            });

            Thread TeacherThread = new Thread(() =>
            {
                TeacherRepository = new Repository <Teacher>(Path + "Teachers.cdat");
                TeacherRepository.Load();
            });

            StudentThread.Start();
            GroupThread.Start();
            SubjectThread.Start();
            TeacherThread.Start();

            while (StudentThread.IsAlive || GroupThread.IsAlive ||
                   SubjectThread.IsAlive || TeacherThread.IsAlive)
            {
                Console.Clear();
                Console.Write("Wait");
                for (int i = 0; i < 5; i++)
                {
                    Thread.Sleep(500);
                    Console.Write(".");
                }
            }
            Console.Clear();
            CommandDictionary = new Dictionary <string, Command>();

            StudentControll = new StudentController(StudentRepository);
            TeacherControll = new TeacherController(TeacherRepository);
            GroupControll   = new GroupController(GroupRepository);
            SearchControll  = new SearchController(StudentRepository, GroupRepository, SubjectRepository);

            // COMMANDS
            CommandDictionary.Add("add student", new Command("add student", "Add new student;"));
            CommandDictionary.Add("add group", new Command("add group", "Add new group;"));
            CommandDictionary.Add("show students", new Command("show students", "Show list of students"));
            CommandDictionary.Add("show groups", new Command("show groups", "Show list of groups"));
            CommandDictionary.Add("student info", new Command("student info", "Show information about student"));
            CommandDictionary.Add("group info", new Command("group info", "Show information about group"));
            CommandDictionary.Add("add subject", new Command("add subject", "Add new subject;"));
            CommandDictionary.Add("add teacher", new Command("add teacher", "Add new teacher;"));
            CommandDictionary.Add("add student to group", new Command("add student to group", "Add student to group"));
            CommandDictionary.Add("add teacher to group", new Command("add teacher to group", "Add teacher to group"));
            CommandDictionary.Add("set subject teacher", new Command("set subject teacher", "Set teacher for subject"));
            CommandDictionary.Add("find students by group", new Command("find students by group", "View all students of group"));
            CommandDictionary.Add("find students by teacher", new Command("find students by teacher", "View all students of teacher"));
            CommandDictionary.Add("find students by subject", new Command("find students by subject", "View all students of subject"));
            CommandDictionary.Add("clr", new Command("clr", "Delete all inforamation from screen"));
            CommandDictionary.Add("exit", new Command("exit", "Close the application;"));
            CommandDictionary.Add("help", new Command("help", "Information about all commands;"));

            // ACTION OF COMMANDS
            CommandDictionary["add group"].SetAction(() =>
            {
                GroupControll.AddGroup(GetGroup());
            });

            CommandDictionary["add subject"].SetAction(() =>
            {
                SubjectRepository.Add(GetSubject());
            });

            CommandDictionary["add teacher"].SetAction(() =>
            {
                TeacherRepository.Add(GetTeacher());
            });

            CommandDictionary["add student"].SetAction(() =>
            {
                StudentControll.AddStudent(GetStudent());
            });

            CommandDictionary["add teacher to group"].SetAction(() =>
            {
                var groupId   = GetId("group");
                var teacherId = GetId("teacher");
                GroupControll.GetGroup(groupId).AddTeacher(teacherId);
            });

            CommandDictionary["add student to group"].SetAction(() =>
            {
                var groupId   = GetId("group");
                var studentId = GetId("student");
                GroupControll.GetGroup(groupId).AddStudent(studentId);
            });

            CommandDictionary["set subject teacher"].SetAction(() =>
            {
                var subId     = GetId("subject");
                var teacherId = GetId("teacher");
                SubjectRepository[subId].SetTeacher(teacherId);
            });

            CommandDictionary["show students"].SetAction(() =>
            {
                var listOfStudents = StudentControll.GetAll();
                Console.WriteLine("Students:");
                Console.WriteLine("--------------------------------------");
                foreach (Student student in listOfStudents)
                {
                    Console.WriteLine("Id: {0}; Name: {1}; Surname: {2};",
                                      student.Id, student.Name, student.Surname);
                }
                Console.WriteLine("--------------------------------------");
            });

            CommandDictionary["show groups"].SetAction(() =>
            {
                var listOfGroups = GroupControll.GetAll();
                Console.WriteLine("Groups:");
                Console.WriteLine("--------------------------------------");
                foreach (ISGroup group in listOfGroups)
                {
                    Console.WriteLine("Id: {0}; Number: {1};", group.Id, group.Number);
                }
                Console.WriteLine("--------------------------------------");
            });

            CommandDictionary["group info"].SetAction(() =>
            {
                ISGroup group = GroupControll.GetGroup(GetId("group"));
                Console.WriteLine("Group:{0}", group.Id);
                Console.WriteLine("Number:{0}", group.Number);
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Students:");
                foreach (int id in group.StudentIDs)
                {
                    Student student = StudentControll.GetStudent(id);
                    Console.WriteLine("Id: {0}; Name: {1}; Surname: {2};", id, student.Name, student.Surname);
                }
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Teachers that teach group:");
                foreach (int id in group.TeacherIDs)
                {
                    Teacher queryTeacher = TeacherRepository
                                           .Where(teacher => teacher.Id == id).Single();
                    Console.WriteLine("Id: {0}; Name: {1}; Surname: {2};", id, queryTeacher.Name, queryTeacher.Surname);
                }
                Console.WriteLine("--------------------------------------");
            });

            CommandDictionary["student info"].SetAction(() =>
            {
                Student student = StudentControll.GetStudent(GetId("student"));
                Console.WriteLine("----------------------------------------");
                Console.WriteLine("Id: {0};", student.Id);
                Console.WriteLine("Name: {0};", student.Name);
                Console.WriteLine("Surname: {0};", student.Surname);
                Console.WriteLine("Course: {0};", student.Course);
                Console.WriteLine("Course: {0};", student.GradeBook);
                Console.WriteLine("Address: {0};", student.Address);
                Console.WriteLine("Mobile number: {0};", student.MobilePhone);
                Console.WriteLine("----------------------------------------");
            });

            CommandDictionary["find students by group"].SetAction(() =>
            {
                var listOfStudents = SearchControll.SearchByGroup(GetId("group"));
                foreach (Student student in listOfStudents)
                {
                    Console.WriteLine("Id: {0}; Name: {1}; Surname: {2};", student.Id, student.Name, student.Surname);
                }
            });

            CommandDictionary["find students by teacher"].SetAction(() =>
            {
                var listOfStudents = SearchControll.SearchByTeacher(GetId("teacher"));
                foreach (Student student in listOfStudents)
                {
                    Console.WriteLine("Id: {0}; Name: {1}; Surname: {2};", student.Id, student.Name, student.Surname);
                }
            });

            CommandDictionary["find students by subject"].SetAction(() =>
            {
                var listOfStudents = SearchControll.SearchByGroup(GetId("subject"));
                foreach (Student student in listOfStudents)
                {
                    Console.WriteLine("Id: {0}; Name: {1}; Surname: {2};", student.Id, student.Name, student.Surname);
                }
            });

            CommandDictionary["help"].SetAction(() =>
            {
                foreach (Command item in CommandDictionary.Values)
                {
                    Console.WriteLine("{0} : {1}", item.Text, item.Description);
                }
            });

            CommandDictionary["clr"].SetAction(() =>
            {
                Console.Clear();
            });

            CommandDictionary["exit"].SetAction(() =>
            {
                Console.WriteLine("Okey :( Good bye!");
                Exit();
                Environment.Exit(0);
            });

            MainMenu();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Change group in repository
 /// </summary>
 /// <param name="oldGroup">Group that will be delete from repository</param>
 /// <param name="newGroup">Group that will be added to repository</param>
 public void ChangeGroup(ISGroup oldGroup, ISGroup newGroup)
 {
     DataRepo.Remove(oldGroup);
     DataRepo.Add(newGroup);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Remove group from repository
 /// </summary>
 /// <param name="delGroup">Group that will be removed from repository</param>
 public void RemoveGroup(ISGroup delGroup)
 {
     DataRepo.Remove(delGroup);
 }