Example #1
0
        public void ListOfStudents(IndividualProjectDBModel iPModel)
        {
            var studentList = iPModel.Students.ToList();

            Console.WriteLine("Firstname --- Lastname --- DateOfBirth --- TuitionFees");
            int counter = 1;

            foreach (var std in studentList)
            {
                Console.WriteLine(
                    $"#{counter} {std.firstName} --- {std.lastName} --- {std.dateOfBirth:dd / MM / yyyy} --- {std.tuitionFees}");
                counter++;
            }
        }
        public void ListOfAssignments(IndividualProjectDBModel iPModel)
        {
            var assignmentList = iPModel.Assignments.ToList();

            Console.WriteLine("Title --- Description --- SubDateTime --- OralMark --- TotalMark");
            int counter = 1;

            foreach (var asn in assignmentList)
            {
                Console.WriteLine($"#{counter} {asn.title} --- {asn.description} --- {asn.subDateTime:dd / MM / yyyy} --- " +
                                  $"{asn.oralMark} --- {asn.totalMark}");
                counter++;
            }
        }
        public void AssignmentsPerCoursePerStudent(IndividualProjectDBModel iPModel)
        {
            var assignmentsPerCoursePerStudent =
                iPModel.Assignments.Include(a => a.Courses.Select(c => c.Students)).ToList();

            foreach (var a in assignmentsPerCoursePerStudent)
            {
                foreach (var c in a.Courses)
                {
                    foreach (var s in c.Students)
                    {
                        Console.WriteLine($"Assignment {a.title} {a.description} " +
                                          $"has {c.title} {c.stream} {c.type} course and {s.firstName} {s.lastName} student");
                    }
                }
            }
        }
 public void ShowStudentsAssignmentsBasedOnCourseNumber(IndividualProjectDBModel iPModel)
 {
     try
     {
         var courseList = iPModel.Courses.ToList();
         Console.WriteLine("Type number(#) of course");
         string isCrsInt = Console.ReadLine();
         int    crsCounter;
         while (!int.TryParse(isCrsInt, out crsCounter) || crsCounter <= 0 || crsCounter > courseList.Count)
         {
             Console.WriteLine("That's not a valid course, please retry");
             isCrsInt = Console.ReadLine();
         }
         for (int i = 0; i < courseList.Count; i++)
         {
             if (i == crsCounter - 1)
             {
                 var cid = courseList[i].courseId;
                 var studentsAssignmentsBasedOnCourse = iPModel.Courses.Include(c => c.Students).Include(c => c.Assignments)
                                                        .Where(c => c.courseId == cid).ToList();
                 foreach (var c in studentsAssignmentsBasedOnCourse)
                 {
                     foreach (var s in c.Students)
                     {
                         foreach (var a in c.Assignments)
                         {
                             Console.WriteLine($"Course {c.title} {c.stream} {c.type} has {s.firstName} {s.lastName} student " +
                                               $"and {a.title} {a.description} assignment");
                         }
                     }
                 }
                 break;
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #5
0
 public void AddTrainersPerCourse(IndividualProjectDBModel iPModel)
 {
     try
     {
         var trainerList = iPModel.Trainers.ToList();
         var courseList  = iPModel.Courses.ToList();
         Console.WriteLine("Type number(#) of course");
         string isCrsInt = Console.ReadLine();
         int    crsCounter;
         while (!int.TryParse(isCrsInt, out crsCounter) || crsCounter <= 0 || crsCounter > courseList.Count)
         {
             Console.WriteLine("That's not a valid course, please retry");
             isCrsInt = Console.ReadLine();
         }
         Console.WriteLine($"How many trainers do you want to add to course #{crsCounter}?");
         string isTrnInt = Console.ReadLine();
         int    trainerNumber;
         while (!int.TryParse(isTrnInt, out trainerNumber) || trainerNumber <= 0 || trainerNumber > trainerList.Count)
         {
             Console.WriteLine("Invalid input, please retry");
             isTrnInt = Console.ReadLine();
         }
         Console.WriteLine("Type number(#) of trainer to add");
         var cid = 0;
         for (int i = 0; i < trainerNumber; i++)
         {
             string isInt = Console.ReadLine();
             int    trnCounter;
             while (!int.TryParse(isInt, out trnCounter) || trnCounter <= 0 || trnCounter > trainerList.Count)
             {
                 Console.WriteLine("That's not a valid trainer, please retry");
                 isInt = Console.ReadLine();
             }
             var tid = 0;
             for (int j = 0; j < trainerList.Count; j++)
             {
                 if (j == trnCounter - 1)
                 {
                     tid = trainerList[j].trainerId;
                     break;
                 }
             }
             for (int k = 0; k < courseList.Count; k++)
             {
                 if (k == crsCounter - 1)
                 {
                     cid = courseList[k].courseId;
                     break;
                 }
             }
             var addTrainerInCourse = iPModel.Trainers
                                      .Include(t => t.Courses).FirstOrDefault(t => t.trainerId == tid);
             var courseToAddTrainer = iPModel.Courses.Find(cid);
             addTrainerInCourse?.Courses.Add(courseToAddTrainer);
             int rowsAffected = iPModel.SaveChanges();
             if (rowsAffected == 0)
             {
                 Console.WriteLine($"Data couldn't be inserted because trainer #{trnCounter} already has course #{crsCounter}");
             }
             if (i < trainerNumber - 1)
             {
                 Console.WriteLine("Type number(#) of new trainer to add");
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #6
0
 public void AddCourses(IndividualProjectDBModel iPModel, int courseListCount)
 {
     try
     {
         Console.WriteLine("Type number of courses to add");
         string isInt = Console.ReadLine();
         int    courseNumber;
         while (!int.TryParse(isInt, out courseNumber) || courseNumber <= 0)
         {
             Console.WriteLine("Invalid input, please retry");
             isInt = Console.ReadLine();
         }
         Console.WriteLine("Type course's properties in the following order:\n" +
                           "Title --- Stream --- Type --- Start_Date (DD/MM/YYYY) --- End_Date (DD/MM/YYYY)");
         for (int i = 0; i < courseNumber; i++)
         {
             Course course = new Course();
             string tl     = Console.ReadLine();
             while (!Regex.IsMatch(tl, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$", RegexOptions.IgnoreCase))
             {
                 Console.WriteLine("Invalid input, please enter valid characters for Title");
                 tl = Console.ReadLine();
             }
             course.title = tl;
             string stm = Console.ReadLine();
             while (!Regex.IsMatch(stm, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$", RegexOptions.IgnoreCase))
             {
                 Console.WriteLine("Invalid input, please enter valid characters for Stream");
                 stm = Console.ReadLine();
             }
             course.stream = stm;
             string tp = Console.ReadLine();
             while (!Regex.IsMatch(tp, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$", RegexOptions.IgnoreCase))
             {
                 Console.WriteLine("Invalid input, please enter valid characters for Type");
                 tp = Console.ReadLine();
             }
             course.type = tp;
             string   isStartDate = Console.ReadLine();
             DateTime startDate;
             while (!DateTime.TryParseExact(isStartDate, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out startDate))
             {
                 Console.WriteLine("Invalid input, please enter a valid Date(e.g., 05/06/2020)");
                 isStartDate = Console.ReadLine();
             }
             course.start_date = startDate;
             string   isEndDate = Console.ReadLine();
             DateTime endDate;
             while (!DateTime.TryParseExact(isEndDate, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out endDate))
             {
                 Console.WriteLine("Invalid input, please enter a valid Date(e.g., 05/06/2020)");
                 isEndDate = Console.ReadLine();
             }
             course.end_date = endDate;
             iPModel.Courses.Add(course);
             iPModel.SaveChanges();
             if (i < courseNumber - 1)
             {
                 Console.WriteLine("Type properties of new course");
             }
         }
         List <Course> courseList       = iPModel.Courses.ToList();
         var           addedCoursesList = courseList.Skip(courseListCount).ToList();
         Console.WriteLine("List of added courses:");
         foreach (var crs in addedCoursesList)
         {
             Console.WriteLine($"{crs.title} --- {crs.stream} --- {crs.type} --- {crs.start_date:dd / MM / yyyy} --- {crs.end_date:dd / MM / yyyy}");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #7
0
        public void AddStudents(IndividualProjectDBModel iPModel, int studentListCount)
        {
            try
            {
                Console.WriteLine("Type number of students to add");
                string isInt = Console.ReadLine();
                int    studentNumber;
                while (!int.TryParse(isInt, out studentNumber) || studentNumber <= 0)
                {
                    Console.WriteLine("Invalid input, please retry");
                    isInt = Console.ReadLine();
                }

                Console.WriteLine("Type student's properties in the following order:\n" +
                                  "First Name --- Last Name --- Date Of Birth (DD/MM/YYYY) --- Tuition Fees (Decimal)");
                for (int i = 0; i < studentNumber; i++)
                {
                    Student student = new Student();
                    string  firstN  = Console.ReadLine();
                    while (!Regex.IsMatch(firstN, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$", RegexOptions.IgnoreCase))
                    {
                        Console.WriteLine("Invalid input, please enter valid characters for First Name");
                        firstN = Console.ReadLine();
                    }

                    student.firstName = firstN;
                    string lastN = Console.ReadLine();
                    while (!Regex.IsMatch(lastN, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$"))
                    {
                        Console.WriteLine("Invalid input, please enter valid characters for Last Name");
                        lastN = Console.ReadLine();
                    }

                    student.lastName = lastN;
                    string   isDateOfBirth = Console.ReadLine();
                    DateTime dtOfBirth;
                    while (!DateTime.TryParseExact(isDateOfBirth, "dd/MM/yyyy", null,
                                                   System.Globalization.DateTimeStyles.None, out dtOfBirth))
                    {
                        Console.WriteLine("Invalid input, please enter a valid Date(e.g., 05/06/2020)");
                        isDateOfBirth = Console.ReadLine();
                    }

                    student.dateOfBirth = dtOfBirth;
                    string  isTuitionFees = Console.ReadLine();
                    decimal tuitionF;
                    while (!decimal.TryParse(isTuitionFees, out tuitionF) || tuitionF <= 0)
                    {
                        Console.WriteLine("Invalid input, please retry");
                        isTuitionFees = Console.ReadLine();
                    }

                    student.tuitionFees = tuitionF;
                    iPModel.Students.Add(student);
                    iPModel.SaveChanges();
                    if (i < studentNumber - 1)
                    {
                        Console.WriteLine("Type properties of new student");
                    }
                }

                List <Student> studentList       = iPModel.Students.ToList();
                var            addedStudentsList = studentList.Skip(studentListCount).ToList();
                Console.WriteLine("List of added students:");
                foreach (var std in addedStudentsList)
                {
                    Console.WriteLine(
                        $"{std.firstName} --- {std.lastName} --- {std.dateOfBirth:dd / MM / yyyy} --- {std.tuitionFees}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #8
0
        public void AddStudentsPerCourse(IndividualProjectDBModel iPModel)
        {
            try
            {
                var studentList = iPModel.Students.ToList();
                var courseList  = iPModel.Courses.ToList();
                Console.WriteLine("Type number(#) of course");
                string isCrsInt = Console.ReadLine();
                int    crsCounter;
                while (!int.TryParse(isCrsInt, out crsCounter) || crsCounter <= 0 || crsCounter > courseList.Count)
                {
                    Console.WriteLine("That's not a valid course, please retry");
                    isCrsInt = Console.ReadLine();
                }

                Console.WriteLine($"How many students do you want to add to course #{crsCounter}?");
                string isStdInt = Console.ReadLine();
                int    studentNumber;
                while (!int.TryParse(isStdInt, out studentNumber) || studentNumber <= 0 ||
                       studentNumber > studentList.Count)
                {
                    Console.WriteLine("Invalid input, please retry");
                    isStdInt = Console.ReadLine();
                }

                Console.WriteLine("Type number(#) of student to add");
                var cid = 0;
                for (int i = 0; i < studentNumber; i++)
                {
                    string isInt = Console.ReadLine();
                    int    stdCounter;
                    while (!int.TryParse(isInt, out stdCounter) || stdCounter <= 0 || stdCounter > studentList.Count)
                    {
                        Console.WriteLine("That's not a valid student, please retry");
                        isInt = Console.ReadLine();
                    }

                    var sid = 0;
                    for (int j = 0; j < studentList.Count; j++)
                    {
                        if (j == stdCounter - 1)
                        {
                            sid = studentList[j].studentId;
                            break;
                        }
                    }

                    for (int k = 0; k < courseList.Count; k++)
                    {
                        if (k == crsCounter - 1)
                        {
                            cid = courseList[k].courseId;
                            break;
                        }
                    }

                    var addStudentInCourse = iPModel.Students
                                             .Include(s => s.Courses).FirstOrDefault(s => s.studentId == sid);
                    var courseToAddStudent = iPModel.Courses.Find(cid);
                    addStudentInCourse?.Courses.Add(courseToAddStudent);
                    int rowsAffected = iPModel.SaveChanges();
                    if (rowsAffected == 0)
                    {
                        Console.WriteLine(
                            $"Data couldn't be inserted because student #{stdCounter} already has course #{crsCounter}");
                    }

                    if (i < studentNumber - 1)
                    {
                        Console.WriteLine("Type number(#) of new student to add");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
 public void AddAssignments(IndividualProjectDBModel iPModel, int assignmentListCount)
 {
     try
     {
         Console.WriteLine("Type number of assignments to add");
         string isInt = Console.ReadLine();
         int    assignmentNumber;
         while (!int.TryParse(isInt, out assignmentNumber) || assignmentNumber <= 0)
         {
             Console.WriteLine("Invalid input, please retry");
             isInt = Console.ReadLine();
         }
         Console.WriteLine("Type assignment's properties in the following order:\n" +
                           "Title --- Description --- SubDateTime (DD/MM/YYYY) --- OralMark (Decimal) --- TotalMark (Decimal)");
         for (int i = 0; i < assignmentNumber; i++)
         {
             Assignment assignment = new Assignment();
             string     tl         = Console.ReadLine();
             while (!Regex.IsMatch(tl, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$", RegexOptions.IgnoreCase))
             {
                 Console.WriteLine("Invalid input, please enter valid characters for Title");
                 tl = Console.ReadLine();
             }
             assignment.title = tl;
             string dcr = Console.ReadLine();
             while (!Regex.IsMatch(dcr, "^[A-Za-z ][A-Za-z0-9!@#$%^&* ]*$", RegexOptions.IgnoreCase))
             {
                 Console.WriteLine("Invalid input, please enter valid characters for Description");
                 dcr = Console.ReadLine();
             }
             assignment.description = dcr;
             string   isSubDateTime = Console.ReadLine();
             DateTime subDtTime;
             while (!DateTime.TryParseExact(isSubDateTime, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out subDtTime))
             {
                 Console.WriteLine("Invalid input, please enter a valid Date(e.g., 05/06/2020)");
                 isSubDateTime = Console.ReadLine();
             }
             assignment.subDateTime = subDtTime;
             string  isOralMark = Console.ReadLine();
             decimal oralMrk;
             while (!decimal.TryParse(isOralMark, out oralMrk) || oralMrk <= 0)
             {
                 Console.WriteLine("Invalid input, please retry");
                 isOralMark = Console.ReadLine();
             }
             assignment.oralMark = oralMrk;
             string  isTotalMark = Console.ReadLine();
             decimal totalMrk;
             while (!decimal.TryParse(isTotalMark, out totalMrk) || totalMrk <= 0)
             {
                 Console.WriteLine("Invalid input, please retry");
                 isTotalMark = Console.ReadLine();
             }
             assignment.totalMark = totalMrk;
             iPModel.Assignments.Add(assignment);
             iPModel.SaveChanges();
             if (i < assignmentNumber - 1)
             {
                 Console.WriteLine("Type properties of new assignment");
             }
         }
         List <Assignment> assignmentList = iPModel.Assignments.ToList();
         var addedAssignmentsList         = assignmentList.Skip(assignmentListCount).ToList();
         Console.WriteLine("List of added assignments:");
         foreach (var asn in addedAssignmentsList)
         {
             Console.WriteLine($"{asn.title} --- {asn.description} --- {asn.subDateTime:dd / MM / yyyy} --- {asn.oralMark} --- {asn.totalMark}");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }