public Domain.Entities.Student Add(Domain.Entities.Student entity)
        {
            if (!_person.CheckIfExists(entity.Person))
            {
                try
                {
                    _person.Add(entity.Person);
                }
                catch (Exception ex)
                {
                    entity.AddError(ex.Message);
                    return(entity);
                }
            }

            if (VerifyStudentAlreadyEnrolled(entity))
            {
                entity.AddError("Estudante já matriculado");
                return(entity);
            }

            //TODO INCLUIR VERIFICAÇÃO SE ESTUDANTE TENTANDO SE MATRICULAR É PROFESSOR NO CURSO
            entity.EnrollmentID = GenerateEnrollmentID(entity);

            entity.Status = EEnrollmentStatus.WAITING_APROVEMENT;

            _studentRepository.Add(entity);

            //check if the person is a professor
            return(entity);
        }
        public ValidationResult Update(Domain.Entities.Student entity)
        {
            var currentStudent = GetById(entity.Id.Value);

            if (currentStudent == null)
            {
                throw new ArgumentNullException("Estudante não encontrado na base de dados.");
            }

            var validationResult = VerifyEnrollmentStatusChanges(currentStudent.Status, entity);

            if (validationResult.Errors.Any())
            {
                return(validationResult);
            }

            if (StatusAvaiableToActivation.Contains(currentStudent.Status) && entity.Status == EEnrollmentStatus.ACTIVE)
            {
                entity.EnrollmentDate = DateTime.Now;
            }

            entity.EnrollmentID = currentStudent.EnrollmentID;

            _studentRepository.Update(entity);

            return(new ValidationResult());
        }
Пример #3
0
        public async Task <StudentDetailsDto> Create(StudentCreationDto studentCreationDto)
        {
            Domain.Entities.Student student = studentMapper.Map(studentCreationDto);
            await writeRepository.AddNewAsync(student);

            await writeRepository.SaveAsync();

            return(studentMapper.Map(student));
        }
        private bool VerifyStudentAlreadyEnrolled(Domain.Entities.Student entity)
        {
            var cpfInformed = entity.Person.Documents.FirstOrDefault(y => y.DocumentTypeId == EDocumentType.CPF);

            if (cpfInformed == null)
            {
                throw new Exception("CPF não informado");
            }

            return(_studentRepository.VerifyStudentAlreadyEnrolled(cpfInformed.DocumentNumber, entity.CourseId));
        }
 public void TestInitialize()
 {
     this._student1            = StudentTestUtils.GetStudent();
     this._student2            = StudentTestUtils.GetStudent();
     this._studentDto1         = StudentTestUtils.GetStudentDetailsDto(_student1.Id);
     this._studentDto2         = StudentTestUtils.GetStudentDetailsDto(_student2.Id);
     this._studentCreationDto  = StudentTestUtils.GetStudentCreationDto();
     this._mockReadRepository  = new Mock <IReadRepository>();
     this._mockWriteRepository = new Mock <IWriteRepository>();
     this._mockStudentMapper   = new Mock <IStudentMapper>();
     _studentService           = new StudentService(_mockReadRepository.Object, _mockWriteRepository.Object,
                                                    _mockStudentMapper.Object);
 }
Пример #6
0
 public StudentFetchingGradeDto Map(Domain.Entities.Student student, GradeDto gradeDto)
 {
     return(new StudentFetchingGradeDto
     {
         Id = student.Id,
         FirstName = student.FirstName,
         LastName = student.LastName,
         Email = student.Email,
         RegistrationNumber = student.RegistrationNumber,
         YearOfStudy = student.YearOfStudy,
         Password = student.Password,
         Grade = gradeDto
     });
 }
Пример #7
0
        public IActionResult FilterEnrollmentsByStudent(string studentDocument)
        {
            try
            {
                var student = new Domain.Entities.Student();


                return(null);
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Пример #8
0
        public StudentDetailsDto Map(Domain.Entities.Student student)
        {
            StudentDetailsDto studentDetailsDto = new StudentDetailsDto
            {
                Id                 = student.Id,
                FirstName          = student.FirstName,
                LastName           = student.LastName,
                Email              = student.Email,
                RegistrationNumber = student.RegistrationNumber,
                YearOfStudy        = student.YearOfStudy,
                Password           = student.Password
            };

            return(studentDetailsDto);
        }
        public static void CreateStudent(Domain.Entities.Student newStudent)
        {
            newStudent.Email     = "*****@*****.**";
            newStudent.Matricule = 1031739;
            Driver.Instance.FindElement(By.Id("Matricule")).SendKeys(newStudent.Matricule.ToString());
            Driver.Instance.FindElement(By.Id("FirstName")).SendKeys(newStudent.FirstName);
            Driver.Instance.FindElement(By.Id("LastName")).SendKeys(newStudent.LastName);
            Driver.Instance.FindElement(By.Id("Telephone")).SendKeys(newStudent.Telephone);
            Driver.Instance.FindElement(By.Id("Password")).SendKeys(newStudent.Password);
            Driver.Instance.FindElement(By.Id("PasswordConfirmation")).SendKeys(newStudent.Password);
            Driver.Instance.FindElement(By.Id("Email")).SendKeys(newStudent.Email);
            Driver.Instance.FindElement(By.Id("ConfirmEmail")).SendKeys(newStudent.Email);

            Driver.Instance.FindElement(By.Id("create-button")).Click();
        }
Пример #10
0
        public IActionResult Put(string id, [FromBody] Domain.Entities.Student entity)
        {
            if (!Guid.TryParse(id, out var idRequested))
            {
                return(BadRequest("Invalid ID Format"));
            }

            var objectUpdated = _studentRepository.Update(entity);

            if (objectUpdated == null)
            {
                return(NotFound());
            }

            return(Redirect("/api/students/" + objectUpdated.Id));
        }
Пример #11
0
            public async Task <CreateStudentDto> Handle(CreateStudentItemCommand request, CancellationToken cancellationToken)
            {
                var entity = new Domain.Entities.Student()
                {
                    FirstName = request.FirstName,
                    LastName  = request.LastName,
                };

                context.Students.Add(entity);
                await context.SaveChangesAsync(cancellationToken);

                return(new CreateStudentDto
                {
                    Id = entity.Id
                });
            }
Пример #12
0
        public async Task <int> Handle(AddStudentCommand request, CancellationToken cancellationToken)
        {
            var student = new Domain.Entities.Student(
                new Guid(),
                request.FirstName,
                request.LastName,
                request.Email,
                request.PhoneNumber,
                request.PhoneNumberTypeId,
                request.Address,
                request.BirthDate,
                request.AdmissionDate);

            context.Student.Add(student);

            await context.SaveChangesAsync(cancellationToken);

            return(student.Id);
        }
        public IActionResult Put(Guid key, [FromBody] Domain.Entities.Student entity)
        {
            try
            {
                var updateResult = _student.Update(entity);

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

                return(Ok(updateResult));
            }
            catch (ArgumentNullException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
        public IActionResult Post([FromBody] Domain.Entities.Student entity)
        {
            try
            {
                var result = _student.Add(entity);

                _unitOfWork.Commit();

                if (!result.Errors.Any())
                {
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest(result.Errors));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
        private string GenerateEnrollmentID(Domain.Entities.Student entity)
        {
            var enrollmentID = $"{DateTime.Now.Year}{(DateTime.Now.Month < 7 ? "01" : "02")}";

            return($"{enrollmentID}_{(_studentRepository.GetAll().Count(d => d.CourseId == entity.CourseId) + 1)}");
        }
Пример #16
0
        public IActionResult Post(Domain.Entities.Student entity)
        {
            var newObject = _studentRepository.Add(entity);

            return(Redirect("/api/students/" + newObject.Id));
        }
Пример #17
0
 public static StudentDto MapToDto(this Domain.Entities.Student entity, int peopleId)
 => new StudentDto()
 {
     Ra       = entity.Ra,
     PeopleId = peopleId
 };
        private ValidationResult VerifyEnrollmentStatusChanges(EEnrollmentStatus currentStatus, Domain.Entities.Student entity)
        {
            var validationResult = new ValidationResult();

            if (currentStatus != EEnrollmentStatus.WAITING_APROVEMENT && entity.Status == EEnrollmentStatus.WAITING_APROVEMENT)
            {
                entity.AddError("Não é possível configurar esta matricula como 'Aguardando Aprovação', pois ela já foi aprovada anteriormente");
                return(validationResult);
            }

            if (currentStatus == EEnrollmentStatus.CANCELED && entity.Status != EEnrollmentStatus.CANCELED)
            {
                entity.AddError("Não é possível alterar o status de uma matricula cancelada.");
                return(validationResult);
            }

            if (StatusAvaiableToSuspension.Contains(currentStatus) && entity.Status == EEnrollmentStatus.SUSPEND)
            {
                entity.AddError($"A matrícula {entity.EnrollmentID} não pode ser cancelada pois está no status {entity.Status}");
                return(validationResult);
            }

            if ((!StatusAvaiableToConclusion.Contains(currentStatus) && entity.Status == EEnrollmentStatus.COMPLETED) || !VerifyIfStudentIsAllowedToCompleteCourse(entity))
            {
                //TODO - RETORNAR NESTE MÉTODO AS PENDÊNCIAS
                entity.AddError($"A matrícula {entity.EnrollmentID} não pode ser concluída pois ainda restam pendências a serem resolvidas.");
                return(validationResult);
            }

            return(validationResult);
        }
 private bool VerifyIfStudentIsAllowedToCompleteCourse(Domain.Entities.Student entity)
 {
     //TODO - Implementar funcionalidade que checa se todas as disciplinas do curso foram cumpridas com a média de aprovação do curso vigente
     return(false);
 }
Пример #20
0
 public Domain.Entities.Student Map(StudentDetailsDto studentDetails, Domain.Entities.Student student)
 {
     autoMapper.Map(studentDetails, student);
     return(student);
 }
Пример #21
0
 public Domain.Entities.Grade Map(GradeCreationDto gradeCreationDto,
                                  Domain.Entities.Student student, Domain.Entities.Exam exam)
 {
     return(new Domain.Entities.Grade(student, exam));
 }