public void CourseShouldThrowInvalidOperationExceptionWhenTryingToAddAStudentTwice()
 {
     var course = new Course("Gosho course");
     var student = new Student("Gosho", 99999);
     course.Add(student);
     course.Add(student);
 }
 public void CourseShouldThrowArgumentOutOfRangeExceptionWhenTryingToAddTooManyStudents()
 {
     var course = new Course("Gosho course");
     for (int i = 0; i < 31; i++)
     {
         var student = new Student("Gosho", 10000 + i);
         course.Add(student);
     }
 }
 public void CourseShouldCorrectlyAddAndRemoveStudentWhenGiveValidData()
 {
     var course = new Course("Gosho course");
     var student = new Student("Gosho", 99999);
     course.Add(student);
     Assert.AreSame(student, course.Students.First());
     course.Remove(student);
     Assert.AreEqual(0, course.Students.Count);
 }
Example #4
0
        public IEnumerable <Course> AddCourse()
        {
            //add
            Course course = new Course();

            course.Name = "Pro";

            Course.Add(course);
            SaveChanges();

            return(Course.ToList());
        }
Example #5
0
        /// <summary>Creates a course for the allClasses class </summary>
        /// <param name="courseName"> The name of the course you wish to initialize</param>
        /// <param name="Task">Is the list of task you wish to add the selected Course</param>
        public void CreateACourse(string courseName, ICollection <string> Task)
        {
            var course = new Course(courseName);

            foreach (var currentTask in Task)
            {
                if (currentTask != string.Empty)
                {
                    course.Add(currentTask);
                }
            }

            this.allClasses.Add(course);
        }
        private void Btn_inscription_Click(object sender, EventArgs e)
        {
            if (cb_lesCourses.SelectedIndex == -1)
            {
                return;
            }
            Course c = (Course)cb_lesCourses.Items[cb_lesCourses.SelectedIndex];

            if (c.Depart)
            {
                c.Add(this.leLap);
                lb_lapinsInscrits.Items.Add(this.leLap);
                this.lesNouveauxParticipants.Add(new Participer(c.GetId(), leLap.GetId(), 0, state.added));
                btn_inscription.Visible = false;
                btn_desinscrire.Visible = true;
            }
        }
Example #7
0
        public ActionResult Update(Course view)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(Edit(view, true));
                }

                view.Description = view.Description.Trim();
                view.Name        = view.Name.Trim();

                if (Equals(view.IdCourse, System.Guid.Empty))
                {
                    var insert = Course.Add(view);

                    if (insert == false)
                    {
                        return(Edit(view, true));
                    }

                    return(RedirectToAction("Index", "Course"));
                }

                var update = Course.Update(view);

                if (update == false)
                {
                    return(Edit(view, true));
                }

                return(RedirectToAction("Index", "Course"));
            }
            catch (Exception e)
            {
                string notes = LogHelper.Notes(view, e.Message);
                Log.Add(Log.TYPE_ERROR, "SistemaMatricula.Controllers.CourseController.Update", notes);
                ViewBag.Message    = "Não foi possível realizar a solicitação. Erro de execução.";
                ViewBag.HideScreen = true;
            }

            return(View("Edit"));
        }
Example #8
0
        /// <summary>
        /// Handles the form's submit action.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            if (!ValidateForm())
            {
                return;
            }

            string   name      = nameTextBox.Text;
            DateTime startDate = startDatePicker.Value;
            DateTime endDate   = endDatePicker.Value;

            if (course == null)
            {
                if (Course.Add(name, startDate, endDate))
                {
                    MessageBox.Show(this, String.Format("Added {0}", name),
                                    "Course Added", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    ResetForm();
                }
                else
                {
                    MessageBox.Show(this, String.Format("Error adding course {0}", name),
                                    "Error Adding Course", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (course.Edit(name, startDate, endDate))
                {
                    MessageBox.Show(this, String.Format("Updated {0}", name),
                                    "Course Updated", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show(this, String.Format("Error updating course {0}", name),
                                    "Error Updating Course", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private async Task ReloadCourses()
        {
            var courses = await DBService.GetAllCourse();

            foreach (var currentCourse in courses)
            {
                Course course = new Course
                {
                    Id           = currentCourse.Id,
                    Name         = currentCourse.Name,
                    StartDate    = currentCourse.StartDate,
                    EndDate      = currentCourse.EndDate,
                    Status       = currentCourse.Status,
                    Notify       = currentCourse.Notify,
                    InstructorId = currentCourse.InstructorId,
                    NoteId       = currentCourse.NoteId
                                   //Assessment = currentCourse.Assessment,
                                   //NoteContent = currentCourse.Note.Contents//,
                                   //InstructorFirstName = currentCourse.Instructor.FirstName,
                                   //InstructorLastName = currentCourse.Instructor.LastName,
                                   //InstructorPhoneNumber = currentCourse.Instructor.PhoneNumber,
                                   //InstructorEmailAddress = currentCourse.Instructor.EmailAddress
                };
                // Called after initialization to force OnPropertyChanged
                if (currentCourse.NoteId != null)
                {
                    //course.NoteContent = currentCourse.Note.Contents;
                }
                else
                {
                    //course.NoteContent = "Sample Note";
                }

                Course.Add(course);
            }
        }
Example #10
0
        public void ExecuteCreate(string[] commandWords)
        {
            string[] cW = commandWords;
            switch (cW[1])
            {
            case "course_participant":
                Person courseParticipant = new CourseParticipant(cW[2], cW[3], cW[4],
                                                                 cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10],
                                                                 this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly,
                                                                 decimal.Parse(cW[13]));
                this.ExecuteAdd(courseParticipant);
                break;

            case "teacher":
                Person teacher = new Teacher(cW[2], cW[3], cW[4],
                                             cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10],
                                             this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly,
                                             decimal.Parse(cW[13]));
                this.ExecuteAdd(teacher);
                break;

            case "secretary":
                Person secretary = new Secretary(cW[2], cW[3], cW[4],
                                                 cW[5], this.ConvertStrintIntoDateTime(cW[6]), cW[7], cW[8], cW[9], cW[10],
                                                 this.ConvertStrintIntoDateTime(cW[11]), ESallaryType.Monthly,
                                                 decimal.Parse(cW[13]));
                this.ExecuteAdd(secretary);
                break;

            case "adult_language_course":
                string courseName                   = CourseInputer.CourseNameCreator(cW[2]);
                ECourseActivityStatus status        = CourseInputer.CourseActivityCreator(cW[3]);
                EGroupType            groupType     = CourseInputer.GroupTypeCreator(cW[4]);
                ECoursePlace          coursePlace   = cW[5] == "local" ? ECoursePlace.Local : ECoursePlace.Online;
                decimal            coursePrice      = decimal.Parse(cW[6]);
                IList <IPerson>    coursists        = CourseInputer.GetCoursistsInCourse(cW[7]);
                IList <IPerson>    teachers         = CourseInputer.GetTeachersInCourse(cW[8]);
                IList <IClassInfo> conductedClasses = new List <IClassInfo>();
                EAge      age                 = EAge.Adults;
                ELanguage language            = CourseInputer.GetLanguage(cW[11]);
                ELanguageLevelForAdults level = CourseInputer.LanguageLevelAdults("a1");
                LanguageCourseForAdults languageCourseAdults = new LanguageCourseForAdults(courseName, status, groupType,
                                                                                           coursePlace, coursePrice, coursists, teachers, conductedClasses, age, language, level);
                Course.Add(languageCourseAdults);
                break;

            case "class":
                ICourse courseToAddToClass = null;

                ulong courseId = ulong.Parse(cW[5].Split('_')[1]);
                foreach (var currentCourse in Course.CourseList)
                {
                    if (currentCourse.Id == courseId)
                    {
                        courseToAddToClass = currentCourse;
                    }
                }

                ITeacher teacherToAddToClass = null;

                ulong teacherId = ulong.Parse(cW[6].Split('_')[1]);
                foreach (var currentTeacher in Person.GetAllTeachers())
                {
                    if (currentTeacher.Id == teacherId)
                    {
                        teacherToAddToClass = (ITeacher)currentTeacher;
                    }
                }

                string[] conductionDateString = cW[2].Split('_')[1].Split('.');
                int      conductionDateYear   = int.Parse(conductionDateString[2]);
                int      conductionDateMonth  = int.Parse(conductionDateString[1]);
                int      conductionDateDay    = int.Parse(conductionDateString[0]);
                DateTime conductionDate       = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay);

                string[] startHourStringArray = cW[3].Split('_')[2].Split(':');
                int      startHourHour        = int.Parse(startHourStringArray[0]);
                int      startHourMinutes     = int.Parse(startHourStringArray[1]);
                DateTime startHour            = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay, startHourHour, startHourMinutes, 0);

                string[] endHourStringArray = cW[4].Split('_')[2].Split(':');
                int      endHourHour        = int.Parse(endHourStringArray[0]);
                int      endHourMinutes     = int.Parse(endHourStringArray[1]);
                DateTime endHour            = new DateTime(conductionDateYear, conductionDateMonth, conductionDateDay, endHourHour, endHourMinutes, 0);

                ClassInfo currentClass = new ClassInfo(conductionDate, startHour, endHour, teacherToAddToClass, courseToAddToClass);

                bool presentTeacher = false;

                foreach (var teacherInCourse in courseToAddToClass.TeachersInCourse)
                {
                    if (teacherInCourse.Id == teacherToAddToClass.Id)
                    {
                        presentTeacher = true;
                        break;
                    }
                }

                if (presentTeacher == true)
                {
                    courseToAddToClass.AddConductedClass(currentClass);
                }
                else
                {
                    throw new ArgumentException(String.Format("There's no teacher with ID {0} who conducts classes in the course with ID {1}",
                                                              teacherToAddToClass.Id, courseToAddToClass.Id));
                }
                break;

            default:
                break;
            }
        }
Example #11
0
        protected void dgCourse_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Course lec = new Course();

            if (e.CommandName == "AddCourse")
            {
                TextBox      txtTempCourseCode  = (TextBox)e.Item.Cells[0].FindControl("txtCourseCodeNew");
                DropDownList txtTempProgrammeID = (DropDownList)e.Item.Cells[1].FindControl("ddlProgrammeIDNew");
                TextBox      txtTempCourseName  = (TextBox)e.Item.Cells[2].FindControl("txtCourseNameNew");

                Regex courseRegex = new Regex(@"^[A-Z ]{4}\d{4}$");
                Match checkCourse = courseRegex.Match(txtTempCourseCode.Text);

                //Validation for name (No digit allowed and only up to 50 characters)
                Regex nameRegex = new Regex(@"[a-zA-Z ]{1,50}$");
                Match checkName = nameRegex.Match(txtTempCourseName.Text);

                if (txtTempCourseCode.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the course code!', 'error')</script>'");
                }
                else if (!checkCourse.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Course code must start with 4 uppercase characters and 4 numbers', 'error')</script>'");
                }
                else if (!checkName.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Course name must consist characters only', 'error')</script>'");
                }
                else if (txtTempProgrammeID.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please select program!', 'error')</script>'");
                }
                else if (txtTempCourseName.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the course name!', 'error')</script>'");
                }
                else
                {
                    if (lec.Add(txtTempCourseCode.Text, txtTempProgrammeID.Text, txtTempCourseName.Text) == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'This course code is existed already, try another course code!', 'error')</script>'");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Added!', text: 'This " + txtTempCourseName.Text + " (" + txtTempCourseCode.Text + ") course is added successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpCourse.aspx'; }});</script>'");
                    }
                }
            }

            else if (e.CommandName == "DeleteCourse")
            {
                Label rowCourseID = (Label)e.Item.Cells[0].FindControl("lblID");

                if (lec.DeleteCourse(rowCourseID.Text) == false)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Delete this course record unsuccessfully', 'error')</script>'");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Deleted!', text: 'Deleted this course record successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpCourse.aspx'; }});</script>'");
                }
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            string errors = IsValid();

            if (!string.IsNullOrEmpty(errors))
            {
                MessageBox.Show(errors, "Validation errors", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                //the checkboxes aren't binded, so we must manually deal with it
                CourseViewModel.Days.Clear();
                if (IsChecked(chkMonday))
                {
                    CourseViewModel.Days.Add(DayOfWeek.Monday);
                }
                if (IsChecked(chkTuesday))
                {
                    CourseViewModel.Days.Add(DayOfWeek.Tuesday);
                }
                if (IsChecked(chkWednesday))
                {
                    CourseViewModel.Days.Add(DayOfWeek.Wednesday);
                }
                if (IsChecked(chkThursday))
                {
                    CourseViewModel.Days.Add(DayOfWeek.Thursday);
                }
                if (IsChecked(chkFriday))
                {
                    CourseViewModel.Days.Add(DayOfWeek.Friday);
                }
                if (IsChecked(chkSaturday))
                {
                    CourseViewModel.Days.Add(DayOfWeek.Saturday);
                }
                try
                {
                    if (editing)
                    {
                        //update in the DB
                        Course.Update(CourseViewModel.Course);
                    }
                    else
                    {
                        Course.Add(CourseViewModel.Course);
                        MainWindow.Instance.lstCourses.Items.Add(CourseViewModel.Course);
                    }
                    Persisted = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to persist course to the database.\n" + ex.Message,
                                    "Sql Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Persisted = false;
                }
                finally
                {
                    Close();
                }
            }
        }
 public void CourseShouldThrowArgumentNullExceptionWhenTryingToAddNullStudent()
 {
     var course = new Course("Gosho course");
     course.Add(null);
 }