Esempio n. 1
0
        internal static void Update(string typeOfData)
        {
            fileRepository = fileFactory.CreateFileManager(typeOfData);
            Student returnedStudent;
            string  id;

            do
            {
                System.Console.WriteLine("Please enter the id of the student:");
                id = System.Console.ReadLine();

                returnedStudent = fileRepository.GetById(id);
            } while (returnedStudent == null);

            Console.WriteLine("Enter the new values:");
            Console.WriteLine("Name:");
            returnedStudent.Name = Console.ReadLine();
            Console.WriteLine("Surname:");
            returnedStudent.Surname = Console.ReadLine();
            Console.WriteLine("Birthday:");
            returnedStudent.Birthday = Console.ReadLine();

            var newReturnedStudent = fileRepository.Update(id, returnedStudent);

            Console.WriteLine(newReturnedStudent);
        }
Esempio n. 2
0
        public static Student AddNewMenu(string typeOfData)
        {
            fileRepository = fileFactory.CreateFileManager(typeOfData);
            Student exist, student;

            do
            {
                student = new Student();
                PropertyInfo[] properties = student.GetType().GetProperties();
                foreach (var p in properties)
                {
                    if (p.Name != "StudentGuid")
                    {
                        System.Console.WriteLine("Plese enter the {0}:", p.Name);
                        var myVal = System.Console.ReadLine();
                        p.SetValue(student, myVal);
                    }
                }
                var students = fileRepository.GetAll();
                exist = (students == null ? null : students.Find(s => s.StudentId == student.StudentId));
            } while (exist != null);
            student.StudentGuid = student.GenerateGuid();

            return(fileRepository.Add(student));
        }
Esempio n. 3
0
        public override AbstractFileManager CreateFileManager(string typeOfFileManager)
        {
            XElement root = XElement.Load("RepositoryConfiguration.xml");
            IEnumerable <XElement> repository =
                from element in root.Elements("Type")
                where (string)element.Attribute("id") == typeOfFileManager
                select element;

            var  fileType                = repository.First().Element("class").Value;
            Type newFileManager          = GetCurrentAssembly().GetType(fileType);
            AbstractFileManager instance = null;

            try
            {
                instance = (AbstractFileManager)Activator.CreateInstance(newFileManager);
            }

            #region Try Catch Exceptions
            catch (ArgumentNullException e)
            {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);

                throw new CustomException(Common_Resources.ArgumentNull, e);
            }
            catch (ArgumentException e)
            {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);

                throw new CustomException(Common_Resources.ArgumentException, e);
            }
            catch (TargetException e)
            {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);

                throw new CustomException(Common_Resources.TargetException, e);
            }
            catch (TargetInvocationException e)
            {
                Log.Error(e.Message);
                Log.Error(e.StackTrace);

                throw new CustomException(Common_Resources.TargetInvocationException, e);
            }
            #endregion

            return(instance);
        }
Esempio n. 4
0
        public static Student SelectById(string typeOfData)
        {
            fileRepository = fileFactory.CreateFileManager(typeOfData);
            Student returnedStudent;

            do
            {
                System.Console.WriteLine("Please enter the id of the student:");
                var id = System.Console.ReadLine();
                returnedStudent = fileRepository.GetById(id);
            } while (returnedStudent == null);

            Console.WriteLine(returnedStudent.StudentGuid.ToString());
            return(returnedStudent);
        }
Esempio n. 5
0
        internal static void GetAll(string typeOfData)
        {
            fileRepository = fileFactory.CreateFileManager(typeOfData);

            var listOfStudents = fileRepository.GetAll();

            if (listOfStudents != null)
            {
                var studentString = "";
                foreach (var s in listOfStudents)
                {
                    studentString = StudentRepository.studentToString(s);
                    System.Console.WriteLine(studentString);
                }
            }
        }
Esempio n. 6
0
        internal static void Remove(string typeOfData)
        {
            fileRepository = fileFactory.CreateFileManager(typeOfData);
            Student deletedStudent, studentToDelete;
            string  id;

            do
            {
                System.Console.WriteLine("Please enter the id of the student:");
                id = System.Console.ReadLine();
                var students = fileRepository.GetAll();
                studentToDelete = students.Find(s => s.StudentId == id);
            } while (studentToDelete == null);
            deletedStudent = fileRepository.Delete(id);
            Console.WriteLine(deletedStudent.StudentGuid.ToString());
        }