public async Task <ProfessorDetailsDto> Create(ProfessorCreatingDto newProfessor)
        {
            Domain.Entities.Professor professor = this.professorMapper.Map(newProfessor);
            await this.writeRepository.AddNewAsync(professor);

            await this.writeRepository.SaveAsync();

            return(this.professorMapper.Map(professor));
        }
 public Domain.Entities.Professor Map(ProfessorCreatingDto professorCreatingDto)
 {
     Domain.Entities.Professor professor = new Domain.Entities.Professor(
         professorCreatingDto.RegistrationNumber,
         professorCreatingDto.Email,
         professorCreatingDto.Password,
         professorCreatingDto.FirstName,
         professorCreatingDto.LastName);
     return(professor);
 }
        public async Task <CourseDto> Create(Guid professorId, CourseCreatingDto newCourse)
        {
            Domain.Entities.Professor professor = await professorService.GetProfessorById(professorId);

            Domain.Entities.Course course = this.courseMapper.Map(newCourse);
            await this.writeRepository.AddNewAsync(course);

            professor.Courses.Add(course);
            await this.writeRepository.SaveAsync();

            return(this.courseMapper.Map(course));
        }
Ejemplo n.º 4
0
 public void TestInitialize()
 {
     this._professor1           = ProfessorTestUtils.GetProfessor();
     this._professor2           = ProfessorTestUtils.GetProfessor();
     this._professorDetailsDto1 = ProfessorTestUtils.GetProfessorDetailsDto(_professor1.Id);
     this._professorDetailsDto2 = ProfessorTestUtils.GetProfessorDetailsDto(_professor2.Id);
     this._professorCreatingDto = ProfessorTestUtils.GetProfessorCreatingDto();
     this._mockReadRepository   = new Mock <IReadRepository>();
     this._mockWriteRepository  = new Mock <IWriteRepository>();
     this._mockProfessorMapper  = new Mock <IProfessorMapper>();
     _professorService          = new ProfessorService(_mockReadRepository.Object, _mockWriteRepository.Object,
                                                       _mockProfessorMapper.Object);
 }
        public ProfessorDetailsDto Map(Domain.Entities.Professor professor)
        {
            ProfessorDetailsDto professorDetailsDto = new ProfessorDetailsDto
            {
                Id = professor.Id,
                RegistrationNumber = professor.RegistrationNumber,
                Email     = professor.Email,
                Password  = professor.Password,
                FirstName = professor.FirstName,
                LastName  = professor.LastName
            };

            return(professorDetailsDto);
        }
Ejemplo n.º 6
0
        public ValidationResult Update(Domain.Entities.Professor entity)
        {
            if (entity.RelatedSubjects.Any())
            {
                var validationResult = VerifyIfProfessorIsACurrentStudentFromClass(entity);

                if (validationResult.Errors.Any())
                {
                    entity.AddError(validationResult.Errors.ToArray());
                    return(entity);
                }
            }

            _professorRepository.Update(entity);
            return(new ValidationResult());
        }
Ejemplo n.º 7
0
        private ValidationResult VerifyIfProfessorIsACurrentStudentFromClass(Domain.Entities.Professor entity)
        {
            var result = _courseClassRepository.GetRelatedSubjects(entity.PersonId)
                         .Where(y =>
            {
                return(entity.RelatedSubjects.Select(t => t.SubjectId).Contains(y.Subject.Id.Value) &&
                       y.Student.Status == Domain.Enum.EEnrollmentStatus.ACTIVE);
            });

            var validationResult = new ValidationResult();

            foreach (var data in result)
            {
                validationResult.AddError($"O usuário {entity.Person.FirstName} não pode lecionar na disciplina {data.Subject.Name}, pois possui uma matrícula: {data.Student.EnrollmentID} em aberto como aluno nesta disciplina.");
            }

            return(validationResult);
        }
Ejemplo n.º 8
0
        public IActionResult Put(Guid id, [FromBody] Domain.Entities.Professor entity)
        {
            try
            {
                var result = _professor.Update(entity);

                _unitOfWork.Commit();

                if (result.Errors.Any())
                {
                    return(BadRequest(result.Errors));
                }

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Ejemplo n.º 9
0
        public Domain.Entities.Professor Add(Domain.Entities.Professor entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("Nenhuma informação de professor enviada");
            }

            if (!_person.CheckIfExists(entity.Person))
            {
                try
                {
                    _person.Add(entity.Person);
                    entity.PersonId = entity.Person.Id.Value;
                }
                catch (Exception ex)
                {
                    entity.AddError(ex.Message);
                    return(entity);
                }
            }

            if (entity.RelatedSubjects.Any())
            {
                var validationResult = VerifyIfProfessorIsACurrentStudentFromClass(entity);

                if (validationResult.Errors.Any())
                {
                    entity.AddError(validationResult.Errors.ToArray());
                    return(entity);
                }
            }

            _professorRepository.Add(entity);

            return(entity);
        }
 private IQueryable <CourseDto> GetAllProfessorCourseDtos(Domain.Entities.Professor professor)
 {
     return(this.readRepository.GetAll <Domain.Entities.Course>()
            .Where(course => course.Professor == professor)
            .Select(course => this.courseMapper.Map(course)));
 }
        public async Task <List <CourseDto> > GetAllForProfessor(Guid professorId)
        {
            Domain.Entities.Professor professor = await professorService.GetProfessorById(professorId);

            return(await GetAllProfessorCourseDtos(professor).ToListAsync());
        }
 public Domain.Entities.Professor Map(ProfessorDetailsDto professorDetails, Domain.Entities.Professor professor)
 {
     this.autoMapper.Map(professorDetails, professor);
     return(professor);
 }