Esempio n. 1
0
        public async Task <Result> UpdateTeacherInfo(UpdateTeacherInfoInput input)
        {
            var teacher =
                await _teacherRespository.GetAllIncluding(teacher => teacher.TeacherStudyGroups)
                .FirstOrDefaultAsync(teacher => teacher.Id == input.TeacherId);

            if (teacher != null)
            {
                if (input.AcademicSubjectId.HasValue)
                {
                    var result =
                        await _academicSubjectService.GetAcademicSubject(
                            new EntityDto <long>(input.AcademicSubjectId.Value));

                    if (result.IsSuccessed)
                    {
                        teacher.AcademicSubjectId = input.AcademicSubjectId;
                    }
                }
                else
                {
                    teacher.AcademicSubjectId = null;
                }
                foreach (var combobox in input.StudyGroupComboboxes)
                {
                    var studyGroupId      = long.Parse(combobox.Value);
                    var teacherStudyGroup =
                        teacher.TeacherStudyGroups.
                        FirstOrDefault(first => first.StudyGroupId == studyGroupId);
                    if (combobox.IsSelected)
                    {
                        if (teacherStudyGroup == null)
                        {
                            teacher.TeacherStudyGroups.Add(
                                new TeacherStudyGroup
                            {
                                TeacherId    = teacher.Id,
                                StudyGroupId = studyGroupId
                            });
                        }
                    }
                    else
                    {
                        if (teacherStudyGroup != null)
                        {
                            teacher.TeacherStudyGroups.Remove(teacherStudyGroup);
                        }
                    }
                }
                await _teacherRespository.UpdateAsync(teacher);

                return(Result.Success());
            }
            return(ErrorNotFoundTeacherWithId(input.TeacherId));
        }
Esempio n. 2
0
 public EditInfoTeacherViewModel()
 {
     Input = new UpdateTeacherInfoInput();
 }