//Conroller = Call the Manager -> Return what was returned public bool AddCourse(Course aNewCourse) { bool confirmation; Courses courseManager = new Courses(); confirmation = courseManager.AddCourse(aNewCourse); return(confirmation); }
//Conroller = Call the Manager -> Return what was returned public bool AddCourse(Course aNewCourse) { Console.WriteLine("HIT"); bool confirmation; Courses courseManager = new Courses(); confirmation = courseManager.AddCourse(aNewCourse); return(confirmation); }
private async void Button_Click_2(object sender, RoutedEventArgs e) { //Check for validation errors string errorList = ""; //if (date_start.SelectedDate == null) // errorList += "Start date cannot be null.\n"; if (num_cost.Value == null || num_fromYear.Value == null || num_level.Value == null || num_pricePerChild == null || num_toYear.Value == null || num_totalSessionsCount.Value == null || num_sessionHours.Value == null) { errorList += "Numeric values cannot be null.\n"; } if (num_fromYear.Value > num_toYear.Value) { errorList += "Start age cannot be higher than end age.\n"; } //if (AllCheckBoxses.Where(x => x.IsChecked == true).Count() == 0) // errorList += "You must choose at least 1 day to continue.\n"; if (Globals.Courses.ToList().Exists(x => x.Value.Name == txt_courseName.Text)) { if (EditedCourse == null || (EditedCourse != null && EditedCourse.Name != txt_courseName.Text)) { errorList += "There exists a course with this name already, please add another name idenitifer.\n"; } } //if (date_start.SelectedDate.Value.Date.CompareTo(DateTime.Now) == -1) // errorList += "The start date must be in the feature.\n"; //bool startDateIsCorrect = false; //AllCheckBoxses.ForEach(x => { // if (x.IsChecked == true && ((DayOfWeek)date_start.SelectedDate.Value.DayOfWeek).ToString() == (string)x.Content) // { // startDateIsCorrect = true; // } //}); //if (startDateIsCorrect == false) // errorList += "The start date must be one of the selected days per week.\n"; //If errors exists show them if (errorList != "") { await this.ShowMessageAsync("Check the following!", errorList); return; } //Initalize new course with the data var course = new Course() { Name = txt_courseName.Text, Cost = Convert.ToInt32(num_cost.Value), AcademicYearStart = Convert.ToInt32(num_fromYear.Value), AcademicYearEnd = Convert.ToInt32(num_toYear.Value), //Full = (bool)toggle_full.IsChecked, //Over = false, Level = Convert.ToInt32(num_level.Value), PricePerChild = Convert.ToInt32(num_pricePerChild.Value), //StartDate = (DateTime)date_start.SelectedDate, TotalSessions = Convert.ToInt32(num_totalSessionsCount.Value), SessionDuration = Convert.ToInt32(num_sessionHours.Value), }; //Add course days per week //foreach (var item in AllCheckBoxses) //{ // if (item.IsChecked == true) // course.DaysPerWeek.Add(item.Content.ToString()); //} try { if (EditedCourse == null) //Check if we are adding a new course or editing existing one. { Courses.AddCourse(course); } else { course.Id = EditedCourse.Id; //course.ShiftedDays = EditedCourse.ShiftedDays; Courses.EditCourse(course); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Globals.RefreshReferenceInformation(); this.Close(); }