コード例 #1
0
        public ActionResult Edit(long id)
        {
            ScienceDTO scienceDto    = new ScienceDTO();
            Teacher    teacherDomain = _teachService.GetItem(id);
            var        config        = new MapperConfiguration(cfg => cfg.CreateMap <Teacher, TeacherDTO>().ForMember(t => t.Science, opt => opt.Ignore()));
            var        mapper        = config.CreateMapper();
            TeacherDTO teacherDto    = mapper.Map <Teacher, TeacherDTO>(teacherDomain);

            teacherDto.Password     = "";
            teacherDto.Science      = scienceDto;
            teacherDto.Science.Id   = teacherDomain.Science.Id;
            teacherDto.Science.Name = teacherDomain.Science.Name;
            foreach (var stud in _studService.GetItemList())
            {
                StudentCheckModel studCheck = new StudentCheckModel
                {
                    Id        = stud.Id,
                    FirstName = stud.FirstName,
                    LastName  = stud.LastName
                };
                if (teacherDomain.Science.Students.Select(s => s.Id).Contains(stud.Id))
                {
                    studCheck.Checked = true;
                }
                teacherDto.Science.Students.Add(studCheck);
            }
            return(View(teacherDto));
        }
コード例 #2
0
        private TeacherDTO CreateTeacherDto(TeacherDTO teacher)
        {
            TeacherDTO teacherDto;

            if (teacher != null)
            {
                teacherDto = teacher;
            }
            ScienceDTO scienceDto = new ScienceDTO();

            teacherDto         = teacher;
            teacherDto.Science = scienceDto;
            var studentsDomain = _studService.GetItemList().ToList();
            var config         = new MapperConfiguration(cfg => cfg.CreateMap <Student, StudentCheckModel>().MaxDepth(3));
            var mapper         = config.CreateMapper();

            teacherDto.Science.Students.AddRange(mapper.Map <List <Student>, List <StudentCheckModel> >(studentsDomain));
            return(teacherDto);
        }
コード例 #3
0
        public ActionResult Details(long id)
        {
            Teacher    teacherDomain = _teachService.GetItem(id);
            TeacherDTO teacherDto    = new TeacherDTO();
            ScienceDTO scienceDto    = new ScienceDTO();

            teacherDto.Science      = scienceDto;
            teacherDto.FirstName    = teacherDomain.FirstName;
            teacherDto.LastName     = teacherDomain.LastName;
            teacherDto.Id           = teacherDomain.Id;
            teacherDto.Login        = teacherDomain.Login;
            teacherDto.Password     = teacherDto.Password;
            teacherDto.Role         = teacherDomain.Role;
            teacherDto.Science.Name = teacherDomain.Science.Name;
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Student, StudentCheckModel>().MaxDepth(3));
            var mapper = config.CreateMapper();

            teacherDto.Science.Students.AddRange(mapper.Map <List <Student>, List <StudentCheckModel> >(_scieService.GetItem(id).Students));
            foreach (var stud in teacherDto.Science.Students)
            {
                teacherDto.Science.Students.First(st => st.Id == stud.Id).Checked = true;
            }
            return(View(teacherDto));
        }