// GetAllTeachers
        public async Task <List <TeacherViewModel> > GetAllTeachers()
        {
            var teachers = await _teacherRepository.GetAllTeachers();

            return(teachers.Select(x => new TeacherViewModel()
            {
                TeacherId = _hashids.Encode(x.Id), TeacherFirstName = x.FirstName, TeacherLastName = x.LastName
            }).ToList());
        }
        public List <SchoolClassViewModel> GetAllSchoolClass()
        {
            var SchoolClassList = _schoolClassRepository.GetSchoolClassList();

            return(SchoolClassList.Select(p => new SchoolClassViewModel
            {
                SchoolClassName = p.Name,
                SchoolClassNumber = _hashidsService.Encode(p.Id)
            }).ToList());
        }
Ejemplo n.º 3
0
        public static void RegisterMappings()
        {
            Mapper.Initialize(cfg => {
                cfg.CreateMap <SchoolClass, SchoolClassViewModel>()
                .ForMember(dest => dest.SchoolClassName, opt => opt.MapFrom(source => source.Name));

                cfg.CreateMap <Mark, MarkViewModel>()
                .ForMember(dest => dest.StudentId, opt => opt.MapFrom(src => _hashidService.Encode(src.StudentId)))
                .ForMember(dest => dest.SubjectId, opt => opt.MapFrom(src => _hashidService.Encode(src.SubjectId)));

                cfg.CreateMap <MarkPostViewModel, Mark>()
                .ForMember(dest => dest.StudentId, opt => opt.MapFrom(src => _hashidService.Decode(src.StudentId)))
                .ForMember(dest => dest.SubjectId, opt => opt.MapFrom(src => _hashidService.Decode(src.SubjectId)));
            });
        }
        ////CHECHKING PART OF CODE////



        //Get Teacher by Class and Subject
        //получить учителя по классу и предмету (не зная id этой связки в таблице-развязке)
        public async Task <TeacherViewModel> GetTeacherBySubjectAndSchoolClass(string subjectNumber, string schoolClassNumber)
        {
            var teacher = await _teacherSclClsSubjRepository.GetTeacherBySubjectAndSchoolClass(_hashidsService.Decode(subjectNumber), _hashidsService.Decode(schoolClassNumber));

            if (teacher != null)
            {
                return(new TeacherViewModel {
                    TeacherFirstName = teacher.FirstName, TeacherLastName = teacher.LastName, TeacherId = _hashidsService.Encode(teacher.Id)
                });
            }
            else
            {
                return(null); //TODO - как красиво кинуть ошибку что нет такой связки?
            }
        }