Exemplo n.º 1
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.ThisWindow = ((Views.EditTeacher)(target));
     return;
     }
     this._contentLoaded = true;
 }
        /// <summary>
        /// The methode AddTeacherCommand use to open a new edit to add the teacher in
        /// </summary>
        private void AddTeacher()
        {
            TeacherEditViewModel teacherEditViewModel = new TeacherEditViewModel();
            var editTeacher = new EditTeacher
            {
                DataContext = teacherEditViewModel
            };
            bool? didListChange = editTeacher.ShowDialog();

            if (didListChange == true)
            {
                addTeachersToPersons();
            }
        }
        /// <summary>
        /// The method the command use to save a Teacher
        /// </summary>
        /// <param name="sender">The EditTeacher window</param>
        private void SaveTeacher(EditTeacher sender)
        {
            TeacherListItemViewData teacherData = (TeacherListItemViewData)PersonData;
                            bool isSaved = false;
            EditTeacher et = sender;
            ICollection<Subject> teacherSubjects = new ObservableCollection<Subject>();

            Teacher teacherModel = new Teacher
            {
                Id = teacherData.Id,
                SocialSecurityNumber = teacherData.SocialSecurityNumber,
                FirstName = teacherData.FirstName,
                LastName = teacherData.LastName,
                Address = teacherData.Address,
                City = teacherData.City,
                ZipCode = teacherData.ZipCode
            };
            foreach (ComboboxItemViewModel item in subjectComboboxItem)
            {
                if (item.IsSelected)
                {
                    teacherModel.Subjects.Add(subjectList.Where(f => f.Id == item.Id).FirstOrDefault());
                }
            }
            foreach (ComboboxItemViewModel item in ClassComboboxItem)
            {
                if (item.IsSelected)
                {
                    teacherModel.Classes.Add(classList.Where(f => f.Id == item.Id).FirstOrDefault());
                }
            }

            using (TeacherContext tc = new TeacherContext())
            {

                if (isEdit)
                {
                    isSaved = tc.EditTeacher(teacherModel);
                }
                else
                {
                    isSaved = tc.AddNewTeacher(teacherModel);
                }
                if (isSaved)
                {
                    et.DialogResult = true;
                    et.Close();
                }
                ErrorMsg = "Teacher did not work";
            }
        }
 /// <summary>
 /// The method the CanselCommand use to Cancel
 /// </summary>
 /// <param name="sender">The EditTeacher window</param>
 private void Cansel(EditTeacher sender)
 {
     EditTeacher et = sender;
     et.DialogResult = false;
     et.Close();
 }