Esempio n. 1
0
        public void Create()
        {
            bool exit;

            while (true)
            {
                ConsoleUI.Clear();

                string baseMessage = "type assignment's information or type 0 to exit \n";


                exit = ConsoleUI.GetString(out string title, $"{baseMessage}Assignment's title: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetString(out string description, $"{baseMessage}Assignment's description: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetDate(out DateTime? submissionDate, "Assignment's date of submsission:\n");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetDecimal(out decimal oralMark, "Assignment's oral mark: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetDecimal(out decimal totalMark, "Assignment's total mark: ");
                if (exit)
                {
                    return;
                }

                int result = DBAssignment.CreateAssignment(title, description, (DateTime)submissionDate, oralMark, totalMark, out int id);

                if (result == 0)
                {
                    ConsoleUI.ShowLine("assignment could NOT be saved");
                }
                else
                {
                    ConsoleUI.ShowLine($"assignment created with id: {id}");
                }

                ConsoleUI.ReadKey();
            }
        }
Esempio n. 2
0
        public static bool IsEmptyDB()
        {
            int UserSize       = DBUser.ReadUsers().Count();
            int AssignmentSize = DBAssignment.ReadAssignments().Count();
            int StudentSize    = DBStudent.ReadStudents().Count();
            int CourseSize     = DBCourse.ReadCourses().Count();
            int TrainerSize    = DBTrainer.ReadTrainers().Count();

            bool basicEntities = UserSize == 0 &&
                                 AssignmentSize == 0 &&
                                 StudentSize == 0 &&
                                 CourseSize == 0 &&
                                 TrainerSize == 0;


            return(basicEntities);
        }
Esempio n. 3
0
        public void Read()
        {
            ICollection <Assignment> assignments = DBAssignment.ReadAssignments();

            if (assignments.Count() == 0)
            {
                ConsoleUI.ShowLine("No assignments yet");
            }
            else
            {
                foreach (Assignment a in assignments)
                {
                    ConsoleUI.ShowLine(a);
                }
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Esempio n. 4
0
        public void Update()
        {
            bool exit;

            ICollection <Assignment> assignments = DBAssignment.ReadAssignments();

            if (assignments.Count() == 0)
            {
                ConsoleUI.ShowLine("No assignments yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select assignment to update, type 0 to exit");
                foreach (Assignment s in assignments)
                {
                    ConsoleUI.ShowLine(s);
                }
            }


            exit = ConsoleUI.GetInt(out int AssignmentID, "give assignment id: ");
            if (exit)
            {
                return;
            }

            ConsoleUI.Clear();

            Assignment assignment;

            try
            {
                assignment = assignments.Where(a => a.Id == AssignmentID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO ASSIGNMENT FOUND WITH ID: {AssignmentID}");
                ConsoleUI.ReadKey();
                return;
            }

            ConsoleUI.ShowLine($"you selected to edit assignment: {assignment.Title}");

            ConsoleUI.ShowLine($"select attribute to edit, type 0 anytime to exit");
            ConsoleUI.ShowLine("1. Title");
            ConsoleUI.ShowLine("2. Description");
            ConsoleUI.ShowLine("3. Date of submission");
            ConsoleUI.ShowLine("4. Oral Mark");
            ConsoleUI.ShowLine("5. Total Mark");

            exit = ConsoleUI.GetInt(out int choice);
            if (exit)
            {
                return;
            }
            ConsoleUI.Clear();

            AssignmentAttributes attribute = (AssignmentAttributes)choice;
            string   newInput = "";
            DateTime?newDate;
            decimal  newMark;

            int result = 0;

            switch (attribute)
            {
            case AssignmentAttributes.Title:
                exit = ConsoleUI.GetString(out newInput, "enter new title: ");
                if (exit)
                {
                    return;
                }

                result = DBAssignment.UpdateAssignment(AssignmentID, attribute, newInput);

                break;

            case AssignmentAttributes.Description:
                exit = ConsoleUI.GetString(out newInput, "enter new description: ");
                if (exit)
                {
                    return;
                }

                result = DBAssignment.UpdateAssignment(AssignmentID, attribute, newInput);

                break;

            case AssignmentAttributes.SubmissionDate:
                exit = ConsoleUI.GetDate(out newDate, "enter new date of submission: ");
                if (exit)
                {
                    return;
                }

                result = DBAssignment.UpdateAssignment(AssignmentID, attribute, newDate);

                break;

            case AssignmentAttributes.OralMark:
                exit = ConsoleUI.GetDecimal(out newMark, "enter new oral mark: ");
                if (exit)
                {
                    return;
                }

                result = DBAssignment.UpdateAssignment(AssignmentID, attribute, newMark);

                break;

            case AssignmentAttributes.TotalMark:
                exit = ConsoleUI.GetDecimal(out newMark, "enter new total mark: ");
                if (exit)
                {
                    return;
                }

                result = DBAssignment.UpdateAssignment(AssignmentID, attribute, newMark);

                break;

            default:
                break;
            }

            if (result == 0)
            {
                ConsoleUI.ShowLine("assignment update failed");
            }
            else
            {
                ConsoleUI.ShowLine("assignment updated successfully");
            }
            ConsoleUI.ReadKey();
        }
Esempio n. 5
0
        public void Delete()
        {
            bool exit;


            ICollection <Assignment> assignments = DBAssignment.ReadAssignments();

            if (assignments.Count() == 0)
            {
                ConsoleUI.ShowLine("No assignments yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select assignment to delete, type 0 to exit");
                foreach (Assignment a in assignments)
                {
                    ConsoleUI.ShowLine(a);
                }
            }


            exit = ConsoleUI.GetInt(out int AssignmentID, "give assignment id: ");
            if (exit)
            {
                return;
            }

            Assignment assignment;

            try
            {
                assignment = assignments.Where(a => a.Id == AssignmentID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO ASSIGNMENT FOUND WITH ID: {AssignmentID}");
                ConsoleUI.ReadKey();
                return;
            }

            bool confirmed = ConsoleUI.GetConfirmation($"are you sure you want to delete assignment {assignment.Title}? [y/n]: ");

            int result = 0;

            if (confirmed)
            {
                result = DBAssignment.DeleteAssignment(AssignmentID);
                if (result == 0)
                {
                    ConsoleUI.ShowLine("delete failed");
                }
                else
                {
                    ConsoleUI.ShowLine("assignment deleted successfully");
                }
                ConsoleUI.ReadKey();
            }
        }
Esempio n. 6
0
        public static void AutoGenerate()
        {
            ConsoleUI.ShowLine("Creating headmaster with username: '******' and password: '******'");

            string encryptedPassword = CryptoManager.EncryptPassword("12345", out string encryptedSalt);

            try
            {
                int headMasterSaved = DBUser.CreateUser("hm", encryptedPassword, encryptedSalt, "headmaster", out int id);
                if (headMasterSaved == 0)
                {
                    throw new Exception("head master NOT saved");
                }
            }
            catch (Exception e)
            {
                ConsoleUI.ShowLine(e.Message);
                ConsoleUI.ReadKey();
                return;
            }

            ConsoleUI.ShowLine("head master created");

            ConsoleUI.ShowLine("creating students");

            List <int> studentIDs    = new List <int>();
            List <int> trainerIDs    = new List <int>();
            List <int> assignmentIDs = new List <int>();
            List <int> courseIDs     = new List <int>();

            int    studentID;
            string studentUsername;
            string plainTextPassword;
            string studentFName;
            string studentLName;

            // 3 students
            for (int i = 0; i < 3; i++)
            {
                studentUsername   = "******" + i;
                plainTextPassword = "******" + i;

                encryptedPassword = CryptoManager.EncryptPassword(plainTextPassword, out encryptedSalt);

                DBUser.CreateUser(studentUsername, encryptedPassword, encryptedSalt, "student", out studentID);

                ConsoleUI.ShowLine($"student user created u:{studentUsername} p:{plainTextPassword}");

                studentFName = "studentFirstName" + i;

                studentLName = "studentLastName" + i;

                DBStudent.CreateStudent(studentFName, studentLName, new DateTime(2000, 1, 1), 20000, studentID);

                ConsoleUI.ShowLine($"student {studentFName} {studentLName} created");

                studentIDs.Add(studentID);

                ConsoleUI.ChangeLine();
            }

            int    trainerID;
            string trainerUsername;
            string trainerFName;
            string trainerLName;
            string trainerSubject;

            // 2 trainers
            for (int i = 0; i < 2; i++)
            {
                trainerUsername   = "******" + i;
                plainTextPassword = "******" + i;

                encryptedPassword = CryptoManager.EncryptPassword(plainTextPassword, out encryptedSalt);

                DBUser.CreateUser(trainerUsername, encryptedPassword, encryptedSalt, "trainer", out trainerID);

                ConsoleUI.ShowLine($"trainer user created u:{trainerUsername} p:{plainTextPassword}");

                trainerFName = "trainerFirstName" + i;

                trainerLName = "trainerLastName" + i;

                trainerSubject = "trainerSubject" + i;

                DBTrainer.CreateTrainer(trainerFName, trainerLName, trainerSubject, trainerID);

                ConsoleUI.ShowLine($"trainer {trainerFName} {trainerLName} created");

                trainerIDs.Add(trainerID);

                ConsoleUI.ChangeLine();
            }

            string title;
            string description;

            // 2 assignments
            for (int i = 0; i < 2; i++)
            {
                title       = "assignmentTitle" + i;
                description = "assignmentDescription" + i;

                DBAssignment.CreateAssignment(title, description, new DateTime(2019, 1, 1), 100, 100, out int assignmentID);

                assignmentIDs.Add(assignmentID);

                ConsoleUI.ShowLine($"assignment {title} with id: {assignmentID} created");

                ConsoleUI.ChangeLine();
            }

            // 3 courses
            for (int i = 0; i < 3; i++)
            {
                title = "courseTitle" + i;

                DBCourse.CreateCourse(title, "C#", "Full time", new DateTime(2019, 1, 1), new DateTime(2019, 2, 2), out int courseID);

                courseIDs.Add(courseID);

                ConsoleUI.ShowLine($"course {title} with id: {courseID} created");

                ConsoleUI.ChangeLine();
            }

            AssignmentPerStudentManager a = new AssignmentPerStudentManager();

            //assignments-courses
            //all assignments to course 1
            #region
            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[0], courseIDs[0]);
            a.CreateFromNewAssignment(assignmentIDs[0], courseIDs[0]);

            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[1], courseIDs[0]);
            a.CreateFromNewAssignment(assignmentIDs[1], courseIDs[0]);

            #endregion

            //first 3 assignments to course 1
            #region
            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[0], courseIDs[1]);
            a.CreateFromNewAssignment(assignmentIDs[0], courseIDs[1]);

            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[1], courseIDs[1]);
            a.CreateFromNewAssignment(assignmentIDs[1], courseIDs[1]);

            #endregion

            //student courses
            //all students to course 1
            #region
            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[0]);
            a.CreateFromNewStudent(studentIDs[0], courseIDs[0]);

            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[1], courseIDs[0]);
            a.CreateFromNewStudent(studentIDs[1], courseIDs[0]);

            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[2], courseIDs[0]);
            a.CreateFromNewStudent(studentIDs[2], courseIDs[0]);

            #endregion

            // 2 students to course 2
            #region
            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[1]);
            a.CreateFromNewStudent(studentIDs[0], courseIDs[1]);

            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[1], courseIDs[1]);
            a.CreateFromNewStudent(studentIDs[1], courseIDs[1]);

            #endregion
            // 2 courses to student 1
            #region
            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[2]);
            a.CreateFromNewStudent(studentIDs[0], courseIDs[2]);

            #endregion


            //trainer courses

            //all trainers to course 1
            #region
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[0]);
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[1], courseIDs[0]);
            #endregion

            // 2 trainers to course 2
            #region
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[1]);
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[1], courseIDs[1]);
            #endregion

            //2 courses to trainer 1
            #region
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[2]);
            #endregion

            ConsoleUI.ShowLine("done");
        }