Ejemplo n.º 1
0
        public CreateEnrollmentResultDTO AddEnrollment(int lectureId, int userId)
        {
            var result = new CreateEnrollmentResultDTO(false, "", null);

            var student = _studentRepository.GetStudentByUserId(userId);

            if (student == null)
            {
                result.Error = "Student not found";

                return(result);
            }
            var lecture = _lectureRepository.GetLectureByID(lectureId);

            if (lecture == null)
            {
                result.Error = "Lecture not found";

                return(result);
            }

            var enrollment = new Enrollment
            {
                EnrollmentDate = DateTime.Now,
                Lecture        = lecture,
                LectureId      = lecture.LectureId,
                Student        = student,
                StudentId      = student.RecordBookNumber,
                Grades         = new List <Grade>()
            };

            var validationResult = EnrollmentsValidator.Validate(enrollment);

            if (!validationResult.IsValid)
            {
                result.Error = validationResult.Message;

                return(result);
            }

            var createdEnrollment = _repository.InsertEnrollment(enrollment);

            if (_repository.Save())
            {
                result.Created    = true;
                result.Enrollment = Mapper.Map <GetEnrollmentDTO>(createdEnrollment);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public GetLectureDTO GetLectureById(int id)
        {
            var lectureEntity = _repository.GetLectureByID(id);

            return(Mapper.Map <GetLectureDTO>(lectureEntity));
        }