예제 #1
0
        public async Task <IActionResult> EditInfoAcademicSubject(long id)
        {
            var returnUrl = NormalizeReturnUrl(null);
            var result    = await _academicSubjectService.GetAcademicSubject(new EntityDto <long>(id));

            if (result.IsSuccessed)
            {
                var academicSubject = result.Value;
                var model           = new EditInfoAcademicSubjectViewModel();
                model.Input.AcademicSubjectId = academicSubject.Id;
                model.Input.Name = academicSubject.Name;
                model.ReturnUrl  = returnUrl;
                var resultGetStudyGroups = await _studyGroupService.GetStudyGroups(new GetStudyGroupsInput());

                if (resultGetStudyGroups.IsSuccessed)
                {
                    var studyGroups = resultGetStudyGroups.Value;
                    foreach (var studyGroup in studyGroups.Items)
                    {
                        var comboboxItem     = new ComboboxItemDto(studyGroup.Id.ToString(), studyGroup.Name);
                        var findedStudyGroup = academicSubject.StudyGroups.FirstOrDefault(studyGroup => studyGroup.Id == studyGroup.Id);
                        if (findedStudyGroup != null)
                        {
                            comboboxItem.IsSelected = true;
                        }
                        model.Input.StudyGroupComboboxes.Add(comboboxItem);
                    }
                }
                return(View(model));
            }
            return(Redirect(returnUrl));
        }
예제 #2
0
        public async Task <IActionResult> EditInfoAcademicSubject(EditInfoAcademicSubjectViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _academicSubjectService.UpdateAcademicSubjectInfo(model.Input);

                if (result.IsSuccessed)
                {
                    return(Redirect(model.ReturnUrl));
                }
                var resultGetAcademicSubject = await _academicSubjectService.GetAcademicSubject(new EntityDto <long>(model.Input.AcademicSubjectId));

                if (resultGetAcademicSubject.IsSuccessed)
                {
                    var academicSubject      = resultGetAcademicSubject.Value;
                    var resultGetStudyGroups = await _studyGroupService.GetStudyGroups(new GetStudyGroupsInput());

                    if (resultGetStudyGroups.IsSuccessed)
                    {
                        var studyGroups = resultGetStudyGroups.Value;
                        foreach (var studyGroup in studyGroups.Items)
                        {
                            var comboboxItem     = new ComboboxItemDto(studyGroup.Id.ToString(), studyGroup.Name);
                            var findedStudyGroup = academicSubject.StudyGroups.FirstOrDefault(studyGroup => studyGroup.Id == studyGroup.Id);
                            if (findedStudyGroup != null)
                            {
                                comboboxItem.IsSelected = true;
                            }
                            model.Input.StudyGroupComboboxes.Add(comboboxItem);
                        }
                    }
                }
                AddResultErros(result);
                AddResultErros(resultGetAcademicSubject);
            }
            return(View(model));
        }