Ejemplo n.º 1
0
        private void teacherEditButton_Click(object sender, EventArgs e)
        {
            var selectedRowIndex = GetSelectedRowIndex(teachersDataGridView);

            if (selectedRowIndex == null)
            {
                return;
            }
            var teacher   = TeachersRepository.GetAll()[(int)selectedRowIndex];
            var teacherVM = new TeacherVM
            {
                Teacher    = teacher,
                SubjectIds = TeacherSubjectRepository.GetSubjectsForTeacher(teacher.Id),
            };

            new DetailedTeacherForm
            (
                teacherVM,
                SubjectsRepository.GetAll(),
                updatedTeacherVM =>
            {
                TeachersRepository.Update(updatedTeacherVM.Teacher);
                TeacherSubjectRepository.UpdateSubjectsForTeacher(updatedTeacherVM.Teacher.Id, updatedTeacherVM.SubjectIds);
                UpdateTeachersGrid();
                return(true);
            }
            ).Show();
        }
        public void EditTeacher(TeacherEntity teacher)
        {
            TeachersRepository teachRepo = new TeachersRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    teachRepo.Update(EntitiesMapper.ToDbModel(teacher), uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error editing teacher " + teacher, ex);
                    throw ex;
                }
            }
        }