Example #1
0
        public void Read()
        {
            ICollection <Course> courses = DBTrainersPerCourse.ReadCoursesWithTrainers();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("No courses yet");
            }
            else
            {
                ConsoleUI.ShowLine("List of courses with trainers\n");
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);

                    ICollection <Trainer> CourseTrainers = c.Trainers.ToList();
                    if (CourseTrainers.Count() == 0)
                    {
                        ConsoleUI.ShowLine("->this course has not trainers\n");
                    }
                    else
                    {
                        foreach (Trainer t in CourseTrainers)
                        {
                            ConsoleUI.ShowMessage("->");
                            ConsoleUI.ShowLine(t);
                        }
                        ConsoleUI.ChangeLine();
                    }
                }
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Example #2
0
        public void Read()
        {
            ICollection <Course> courses = DBAssignmentsPerCourse.ReadCoursesWithAssignments();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("No courses yet");
            }
            else
            {
                ConsoleUI.ShowLine("List of courses with assignments\n");
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);

                    ICollection <Assignment> CourseAssignments = c.Assignments.ToList();
                    if (CourseAssignments.Count() == 0)
                    {
                        ConsoleUI.ShowLine("->this course has not assignments\n");
                    }
                    else
                    {
                        foreach (Assignment a in CourseAssignments)
                        {
                            ConsoleUI.ShowMessage("->");
                            ConsoleUI.ShowLine(a);
                        }
                        ConsoleUI.ChangeLine();
                    }
                }
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Example #3
0
        public void ReadTrainerCourses(int trainerID)
        {
            ICollection <Trainer> trainers = DBTrainersPerCourse.ReadTrainersWithCourses();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("No trainers yet");
            }
            else
            {
                ConsoleUI.ShowLine("List of my courses:\n");

                Trainer me = trainers.Where(t => t.Id == trainerID).First();

                if (me.Courses.Count() == 0)
                {
                    ConsoleUI.ShowLine("I am not enrolled in any course");
                }
                else
                {
                    foreach (Course c in me.Courses)
                    {
                        ConsoleUI.ShowMessage("->");
                        ConsoleUI.ShowLine(c);
                    }
                }

                ConsoleUI.ChangeLine();
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Example #4
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();
            }
        }
        public void SubmitAssignmentPerCoursePerStudent(int studentid)
        {
            ICollection <StudentAssignment> saList = DBAssignmentPerStudent.Read().Where(s => s.StudentId == studentid).ToList();

            if (saList.Count() == 0)
            {
                ConsoleUI.ShowLine("nothing to show");
            }
            else
            {
                ConsoleUI.ShowLine("my assignments");
                foreach (StudentAssignment item in saList)
                {
                    ConsoleUI.ShowLine(item);
                }
            }

            bool exit;

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

            exit = ConsoleUI.GetInt(out int selectedCourse, "give course id: ");
            if (exit)
            {
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }

            int result = DBAssignmentPerStudent.SubmitAssignment(studentid, selectedAssignment, selectedCourse);

            if (result == 0)
            {
                ConsoleUI.ShowLine("error submitting assignment");
            }
            else
            {
                ConsoleUI.ShowLine("assignment submitted successfully");
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Example #6
0
        public void Read()
        {
            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("no trainers yet");
            }
            else
            {
                foreach (Trainer t in trainers)
                {
                    ConsoleUI.ShowLine(t);
                }
            }
            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
        public void Read()
        {
            ICollection <Course> courses = DBCourse.ReadCourses();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("No courses yet");
            }
            else
            {
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);
                }
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Example #8
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();
        }
Example #9
0
        public void Read()
        {
            ICollection <Student> students = DBStudent.ReadStudents();

            if (students.Count() == 0)
            {
                ConsoleUI.ShowLine("No students yet");
            }
            else
            {
                foreach (Student s in students)
                {
                    ConsoleUI.ShowLine(s);
                }
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
        public void ReadAssignmentsPerCoursePerStudent()
        {
            ICollection <StudentAssignment> saList = DBAssignmentPerStudent.Read();

            if (saList.Count() == 0)
            {
                ConsoleUI.ShowLine("nothing to show");
            }
            else
            {
                foreach (StudentAssignment item in saList)
                {
                    ConsoleUI.ShowLine(item);
                }
            }


            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
        public void ReadDueDates(int studentid)
        {
            ICollection <StudentAssignment> saList = DBAssignmentPerStudent.Read().Where(s => s.StudentId == studentid).ToList();

            if (saList.Count() == 0)
            {
                ConsoleUI.ShowLine("nothing to show");
            }
            else
            {
                ConsoleUI.ShowLine("my assignments");
                foreach (StudentAssignment item in saList)
                {
                    Assignment a = item.Assignment;
                    Course     c = item.Course;
                    ConsoleUI.ShowLine($"assignment {a.Id}: {a.Title} by course {c.Id}: {c.Title}, due {a.SubmissionDate}, submitted: {item.Submitted} ");
                }
            }
            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
        public void ReadSchedule(int studentid)
        {
            ICollection <Student> me = DBStudentsPerCourse.ReadStudentWithCourses().Where(s => s.Id == studentid).ToList();

            ICollection <Course> myCourses = me.First().Courses;

            if (myCourses.Count() == 0)
            {
                ConsoleUI.ShowLine("no courses for you at all!!!");
            }
            else
            {
                bool exit;

                exit = ConsoleUI.GetDate(out DateTime? dateToSearch, "give date to search\n");
                if (exit)
                {
                    ConsoleUI.ReadKey();
                    ConsoleUI.Clear();
                    return;
                }

                myCourses = myCourses.Where(c => c.StartDate <dateToSearch && c.EndDate> dateToSearch).ToList();
                if (myCourses.Count() == 0)
                {
                    ConsoleUI.ShowLine("no courses for you for that date");
                }
                else
                {
                    ConsoleUI.ShowLine($"in {dateToSearch} you will be having: ");
                    foreach (Course c in myCourses)
                    {
                        Console.WriteLine(c);
                    }
                }
            }
            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Example #13
0
        /// <summary>
        /// Clear all view content
        /// </summary>
        private void ClearAllDisplayContent()
        {
            lock (_lockUI)
            {
                List <TabPage> removePages = new List <TabPage>();
                ConsoleUI.Clear();
                ChannelUI.Clear();
                foreach (var item in CustomConsoleList)
                {
                    item.Clear();
                }
                int i = 0;
                foreach (TabPage item in TabControlMain.TabPages)
                {
                    IApplicationControl appControl = item.Controls[0] as IApplicationControl;
                    if (null != appControl && !String.IsNullOrWhiteSpace(appControl.ControlName))
                    {
                        item.Text = appControl.ControlName;
                    }

                    if (i > 2)
                    {
                        removePages.Add(item);
                    }

                    i++;
                }
                TabControlMain.TabPages[0].Text = "Console";
                TabControlMain.TabPages[1].Text = "Channels";

                foreach (TabPage item in removePages)
                {
                    TabControlMain.TabPages.Remove(item);
                }
            }
        }
Example #14
0
        public void Delete()
        {
            bool exit;


            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("no trainers yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select trainer to delete, type 0 to exit");
                foreach (Trainer t in trainers)
                {
                    ConsoleUI.ShowLine(t);
                }
            }


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

            Trainer trainer;

            try
            {
                trainer = trainers.Where(t => t.Id == TrainerID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO TRAINER FOUND WITH ID: {TrainerID}");
                ConsoleUI.ReadKey();
                return;
            }

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

            int result = 0;

            if (confirmed)
            {
                try
                {
                    result = DBTrainer.DeleteTrainer(TrainerID);
                    if (result == 0)
                    {
                        throw new Exception("could NOT delete trainer");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                try
                {
                    result = DBUser.DeleteUser(TrainerID);
                    if (result == 0)
                    {
                        throw new Exception("could NOT delete user");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("trainer deleted successfully");

                ConsoleUI.ReadKey();
            }
        }
Example #15
0
        public void Update()
        {
            bool exit;

            ICollection <Student> students = DBStudent.ReadStudents();

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


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

            ConsoleUI.Clear();

            Student student;

            try
            {
                student = students.Where(s => s.Id == StudentID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO STUDENT FOUND WITH ID: {StudentID}");
                ConsoleUI.ReadKey();
                return;
            }

            ConsoleUI.ShowLine($"you selected to edit student: {student.FirstName} {student.LastName}");

            ConsoleUI.ShowLine($"select attribute to edit, type 0 anytime to exit");
            ConsoleUI.ShowLine("1. Username");
            ConsoleUI.ShowLine("2. Password");
            ConsoleUI.ShowLine("3. First name");
            ConsoleUI.ShowLine("4. Last name");
            ConsoleUI.ShowLine("5. Date of birth");
            ConsoleUI.ShowLine("6. Fees");


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

            Object attribute;

            if (choice == 1 || choice == 2)
            {
                attribute = (UserAttributes)choice;
            }
            else
            {
                attribute = (StudentAttributes)choice;
            }

            string   newInput = "";
            DateTime?newDate;
            decimal  newFees;

            int result = 0;

            try
            {
                switch (attribute)
                {
                case StudentAttributes.Fname:
                    exit = ConsoleUI.GetString(out newInput, "enter new first name: ");
                    if (exit)
                    {
                        return;
                    }

                    result = DBStudent.UpdateStudent(StudentID, attribute, newInput);

                    if (result == 0)
                    {
                        throw new Exception("student NOT updated");
                    }

                    break;

                case StudentAttributes.Lname:
                    exit = ConsoleUI.GetString(out newInput, "enter new last name: ");
                    if (exit)
                    {
                        return;
                    }

                    result = DBStudent.UpdateStudent(StudentID, attribute, newInput);

                    if (result == 0)
                    {
                        throw new Exception("student NOT updated");
                    }

                    break;

                case StudentAttributes.DOB:
                    exit = ConsoleUI.GetDate(out newDate, "enter new date of birth: ");
                    if (exit)
                    {
                        return;
                    }

                    result = DBStudent.UpdateStudent(StudentID, attribute, newDate);

                    if (result == 0)
                    {
                        throw new Exception("student NOT updated");
                    }

                    break;

                case StudentAttributes.Fees:
                    exit = ConsoleUI.GetDecimal(out newFees, "enter new fees: ");
                    if (exit)
                    {
                        return;
                    }

                    result = DBStudent.UpdateStudent(StudentID, attribute, newFees);

                    if (result == 0)
                    {
                        throw new Exception("student NOT updated");
                    }

                    break;

                case UserAttributes.Username:
                    exit = ConsoleUI.GetString(out newInput, "enter new username: "******"user NOT updated");
                    }

                    break;

                case UserAttributes.Password:
                    exit = ConsoleUI.GetString(out newInput, "enter new password: "******"user NOT updated");
                    }

                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                ConsoleUI.ShowLine(e.Message);
            }

            ConsoleUI.ShowLine("student updated successfully");

            ConsoleUI.ReadKey();
        }
Example #16
0
        public void Create()
        {
            bool exit;

            while (true)
            {
                ConsoleUI.Clear();

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

                exit = ConsoleUI.GetString(out string username, $"{baseMessage}Student's username: "******"{baseMessage}Student's password: "******"{baseMessage}Student's first name: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetString(out string lname, $"{baseMessage}Student's last name: ");
                if (exit)
                {
                    return;
                }

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

                exit = ConsoleUI.GetDecimal(out decimal fees, "Student's fees: ");
                if (exit)
                {
                    return;
                }

                int studentID;

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

                try
                {
                    int userSaved = DBUser.CreateUser(username, encryptedPassword, encryptedSalt, "student", out studentID);
                    if (userSaved == 0)
                    {
                        throw new Exception("user NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine($"user {username} saved");

                try
                {
                    int studentSaved = DBStudent.CreateStudent(fname, lname, (DateTime)dob, fees, studentID);
                    if (studentSaved == 0)
                    {
                        throw new Exception("student NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("student created");

                ConsoleUI.ReadKey();
            }
        }
Example #17
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();
        }
Example #18
0
        public void Delete()
        {
            bool exit;


            ICollection <Student> students = DBStudent.ReadStudents();

            if (students.Count() == 0)
            {
                ConsoleUI.ShowLine("No students yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select student to delete, type 0 to exit");
                foreach (Student s in students)
                {
                    ConsoleUI.ShowLine(s);
                }
            }


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

            Student student;

            try
            {
                student = students.Where(s => s.Id == StudentID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO STUDENT FOUND WITH ID: {StudentID}");
                ConsoleUI.ReadKey();
                return;
            }

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

            int result = 0;

            if (confirmed)
            {
                try
                {
                    result = DBStudent.DeleteStudent(StudentID);
                    if (result == 0)
                    {
                        throw new Exception("could NOT delete student");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                try
                {
                    result = DBUser.DeleteUser(StudentID);
                    if (result == 0)
                    {
                        throw new Exception("could NOT delete user");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("student deleted successfully");

                ConsoleUI.ReadKey();
            }
        }
Example #19
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();
            }
        }
Example #20
0
 private void clearButton_Click(object sender, System.EventArgs args)
 {
     console.Clear();
 }
Example #21
0
        public void Update()
        {
            bool exit;


            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("No trainers yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select trainer to update, type 0 to exit");
                foreach (Trainer t in trainers)
                {
                    ConsoleUI.ShowLine(t);
                }
            }


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

            ConsoleUI.Clear();

            Trainer trainer;

            try
            {
                trainer = trainers.Where(t => t.Id == TrainerID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO TRAINER FOUND WITH ID: {TrainerID}");
                ConsoleUI.ReadKey();
                return;
            }

            ConsoleUI.ShowLine($"you selected to edit trainer: {trainer.FirstName} {trainer.LastName}");

            ConsoleUI.ShowLine($"select attribute to edit, type 0 anytime to exit");
            ConsoleUI.ShowLine("1. Username");
            ConsoleUI.ShowLine("2. Password");
            ConsoleUI.ShowLine("3. First name");
            ConsoleUI.ShowLine("4. Last name");
            ConsoleUI.ShowLine("5. Subject");

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

            Object attribute;

            if (choice == 1 || choice == 2)
            {
                attribute = (UserAttributes)choice;
            }
            else
            {
                attribute = (TrainerAttributes)choice;
            }

            string newInput = "";


            bool entitySpecificUpdate = false;

            switch (attribute)
            {
            case TrainerAttributes.Fname:
                exit = ConsoleUI.GetString(out newInput, "enter new first name: ");
                entitySpecificUpdate = true;
                break;

            case TrainerAttributes.Lname:
                exit = ConsoleUI.GetString(out newInput, "enter new last name: ");
                entitySpecificUpdate = true;
                break;

            case TrainerAttributes.Subject:
                exit = ConsoleUI.GetString(out newInput, "enter new subject: ");
                entitySpecificUpdate = true;
                break;

            case UserAttributes.Username:
                exit = ConsoleUI.GetString(out newInput, "enter new username: "******"enter new password: "******"trainer update failed");
                    }
                    ConsoleUI.ShowLine("trainer updated successfully");
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }
            }
            else
            {
                try
                {
                    result = DBUser.UpdateUser(TrainerID, attribute, newInput);
                    if (result == 0)
                    {
                        throw new Exception("user update failed");
                    }
                    ConsoleUI.ShowLine("user updated successfully");
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }
            }


            ConsoleUI.ReadKey();
        }
Example #22
0
        public void Create()
        {
            bool exit;

            while (true)
            {
                ConsoleUI.Clear();

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

                exit = ConsoleUI.GetString(out string username, $"{baseMessage}Trainer's username: "******"{baseMessage}Trainer's password: "******"{baseMessage}Trainer's first name: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetString(out string lname, $"{baseMessage}Trainer's last name: ");
                if (exit)
                {
                    return;
                }

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

                int trainerID;

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

                try
                {
                    int userSaved = DBUser.CreateUser(username, encryptedPassword, encryptedSalt, "trainer", out trainerID);
                    if (userSaved == 0)
                    {
                        throw new Exception("user NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine($"user {username} saved");

                try
                {
                    int trainerSaved = DBTrainer.CreateTrainer(fname, lname, subject, trainerID);
                    if (trainerSaved == 0)
                    {
                        throw new Exception("trainer NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("trainer created");

                ConsoleUI.ReadKey();
            }
        }
        public void MarkAssignmentsPerCoursePerStudent()
        {
            ICollection <StudentAssignment> saList = DBAssignmentPerStudent.Read();

            if (saList.Count() == 0)
            {
                ConsoleUI.ShowLine("nothing to show");
            }
            else
            {
                foreach (StudentAssignment item in saList)
                {
                    ConsoleUI.ShowLine(item);
                }
            }

            ConsoleUI.ShowLine("select student, assignment and course to mark or type 0 to exit");
            bool exit;

            exit = ConsoleUI.GetInt(out int selectedStudent, "give student id: ");
            if (exit)
            {
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }

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

            exit = ConsoleUI.GetInt(out int selectedCourse, "give course id: ");
            if (exit)
            {
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }

            StudentAssignment sa = saList.Where(i =>
                                                i.StudentId == selectedStudent &&
                                                i.CourseId == selectedCourse &&
                                                i.AssignmentId == selectedAssignment
                                                ).First();

            if (!sa.Submitted)
            {
                ConsoleUI.ShowLine("this assignment is not yet submitted, please choose another submission");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }

            exit = ConsoleUI.GetInt(out int oralMark, "give new oral mark: ");
            if (exit)
            {
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }

            exit = ConsoleUI.GetInt(out int totalMark, "give new total mark: ");
            if (exit)
            {
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }

            int result = DBAssignmentPerStudent.MarkAssignment(selectedStudent,
                                                               selectedAssignment,
                                                               selectedCourse,
                                                               oralMark,
                                                               totalMark);

            if (result == 0)
            {
                ConsoleUI.ShowLine("error marking assignment");
            }
            else
            {
                ConsoleUI.ShowLine("assignment marked successfully");
            }
            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
        public void Create()
        {
            bool exit;

            while (true)
            {
                ConsoleUI.Clear();

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


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

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

                exit = ConsoleUI.GetInt(out int typeInput, $"{baseMessage}Course's type (1 = Full time, 2 = Part time): ");
                if (exit)
                {
                    return;
                }
                if (typeInput != 1 && typeInput != 2)
                {
                    ConsoleUI.ShowLine("course type not accepted");
                    ConsoleUI.ReadKey();
                    continue;
                }
                string type = typeInput == 1 ? "Full time" : "Part time";

                exit = ConsoleUI.GetDate(out DateTime? startDate, "Course's start date:\n");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetDate(out DateTime? endDate, "Course's end date:\n");
                if (exit)
                {
                    return;
                }

                if (endDate <= startDate)
                {
                    ConsoleUI.ShowLine("invalid dates: end date is before start date, IMPOSSIBRU!!");
                    ConsoleUI.ReadKey();
                    continue;
                }

                int result = DBCourse.CreateCourse(title, stream, type, (DateTime)startDate, (DateTime)endDate, out int id);

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

                ConsoleUI.ReadKey();
            }
        }
        public void Update()
        {
            bool exit;


            ICollection <Course> courses = DBCourse.ReadCourses();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("no courses yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select course to update, type 0 to exit");
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);
                }
            }


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

            ConsoleUI.Clear();

            Course course;

            try
            {
                course = courses.Where(c => c.Id == CourseID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO COURSE FOUND WITH ID: {CourseID}");
                ConsoleUI.ReadKey();
                return;
            }

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

            ConsoleUI.ShowLine($"select attribute to edit, type 0 anytime to exit");
            ConsoleUI.ShowLine("1. Title");
            ConsoleUI.ShowLine("2. Stream");
            ConsoleUI.ShowLine("3. Type");
            ConsoleUI.ShowLine("4. Date of start");
            ConsoleUI.ShowLine("5. Date of end");

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

            CourseAttributes attribute = (CourseAttributes)choice;
            string           newInput  = "";
            DateTime?        newStartDate;
            DateTime?        newEndDate;

            int result = 0;

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

                result = DBCourse.UpdateCourse(CourseID, attribute, newInput);

                break;

            case CourseAttributes.Stream:
                exit = ConsoleUI.GetString(out newInput, "enter new stream: ");
                if (exit)
                {
                    return;
                }

                result = DBCourse.UpdateCourse(CourseID, attribute, newInput);

                break;

            case CourseAttributes.Type:
                exit = ConsoleUI.GetString(out newInput, "enter new type: ");
                if (exit)
                {
                    return;
                }

                result = DBCourse.UpdateCourse(CourseID, attribute, newInput);

                break;

            case CourseAttributes.StartDate:
                exit = ConsoleUI.GetDate(out newStartDate, "enter new start date: ");
                if (exit)
                {
                    return;
                }

                result = DBCourse.UpdateCourse(CourseID, attribute, newStartDate);

                break;

            case CourseAttributes.EndDate:
                exit = ConsoleUI.GetDate(out newEndDate, "enter new end date: ");
                if (exit)
                {
                    return;
                }

                result = DBCourse.UpdateCourse(CourseID, attribute, newEndDate);

                break;

            default:
                break;
            }

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


            ICollection <Course> courses = DBCourse.ReadCourses();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("no courses yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select course to delete, type 0 to exit");
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);
                }
            }


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

            Course course;

            try
            {
                course = courses.Where(c => c.Id == CourseID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO COURSE FOUND WITH ID: {CourseID}");
                ConsoleUI.ReadKey();
                return;
            }

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

            int result = 0;

            if (confirmed)
            {
                result = DBCourse.DeleteCourse(CourseID);
                if (result == 0)
                {
                    ConsoleUI.ShowLine("delete failed");
                }
                else
                {
                    ConsoleUI.ShowLine("course deleted successfully");
                }
                ConsoleUI.ReadKey();
            }
        }