public List <GeneralSelectionItem> GetAllSubjectsAsSelectionItem()
        {
            var subjects = _subjectRepository.FindAll();
            List <GeneralSelectionItem> subjectDTOs = new List <GeneralSelectionItem>();

            subjects.ToList().ForEach(x => subjectDTOs.Add(MapSubject.MapSubjectToGeneralSelectionItem(x)));
            return(subjectDTOs);
        }
        public SubjectDTO GetSubjectById(string subjectId)
        {
            var subject = _subjectRepository.GetSubjectById(subjectId);

            if (subject == null)
            {
                throw new ParameterException("Subject with given id does not exists.");
            }
            return(MapSubject.MapSubjectToSubjectDTO(subject));
        }
        public IEnumerable <GeneralSelectionItem> GetSubjectUserHasPassedAsSubjectDTO(string userId)
        {
            if (userId == null)
            {
                throw new ParameterException("Requested userId cannot be null");
            }
            var subjects       = _subjectRepository.GetSubjectsStudentHasPassed(userId);
            var selectionItems = subjects.Select(x => MapSubject.MapSubjectToGeneralSelectionItem(x));

            return(selectionItems);
        }
        public void CreateSubject(SubjectDTO subjectDTO)
        {
            if (subjectDTO == null)
            {
                throw new ParameterException("subject object cannot be null");
            }
            if (subjectDTO.SubjectID != null)
            {
                throw new ParameterException("subjectID cannot have initial value");
            }
            var sub = MapSubject.MapSubjectDTOToSubject(subjectDTO);

            _subjectRepository.Create(sub);
        }
        public SubjectDTO UpdateSubject(SubjectDTO subject)
        {
            if (subject == null)
            {
                throw new ParameterException("Subject to be updated cannot be null");
            }
            else if (subject.SubjectID == null || String.IsNullOrEmpty(subject.SubjectCode))
            {
                throw new ParameterException("SubjectID, SubjectCode cannot be null or empty");
            }

            var     subjectDBModel = MapSubject.MapSubjectDTOToSubject(subject);
            Subject updated        = _subjectRepository.UpdateSubject(subjectDBModel);

            return(MapSubject.MapSubjectToSubjectDTO(updated));
        }
        public StudentDTO GetStudentDetails(string userID)
        {
            if (userID == null || !Guid.TryParse(userID, out Guid userguid))
                throw new ParameterException("user ID is invalid");
            var currentStudent = _studentRepository.FindStudentByUserID(userID);

            if (currentStudent == null)
                throw new AuthenticationException("Requested student does not exists");

            StudentDTO studentDTO = MapStudent.MapStudentDBModelToStudentDTO(currentStudent);

            var subjectsTutoring = _subjectRepository.GetSubjectsStudentIsTutoring(userID);

            if (subjectsTutoring != null)
            {
                var subjectDtos = subjectsTutoring.Select(x => MapSubject.MapSubjectToGeneralSelectionItem(x));
                studentDTO.TutoringSubjects = subjectDtos;
            }
            return studentDTO;
        }
 public IEnumerable <SubjectListItemDTO> GetAllSubjectAsSubjectListItem()
 {
     return(_subjectRepository.FindAll().Select(x => MapSubject.MapSubjectToSubjectListItemDTO(x)));
 }