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);
        }
Пример #2
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);
        }