Exemplo n.º 1
0
        public List <EnrollmentData> GetEnrollmentDataByStudentID(string index)
        {
            List <EnrollmentData> enrollments = new List <EnrollmentData>();

            using (var connection = new SqlConnection(CONNECTION_STRING))
            {
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "SELECT s.FirstName, s.LastName, st.Name as Studies, e.Semester " +
                                          "FROM Studies st " +
                                          "JOIN Enrollment e on e.IdStudy = st.IdStudy " +
                                          "JOIN Student s on s.IdEnrollment = e.IdEnrollment " +
                                          "WHERE s.IndexNumber = @index";

                    command.Parameters.AddWithValue("@index", index);
                    connection.Open();

                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var enrollment = new EnrollmentData();

                        enrollment.FirstName = reader["FirstName"].ToString();
                        enrollment.LastName  = reader["LastName"].ToString();
                        enrollment.Studies   = reader["Studies"].ToString();
                        enrollment.Semester  = reader["Semester"].ToString();

                        enrollments.Add(enrollment);
                    }
                }
            }

            return(enrollments);
        }
        protected override void Seed(ContosoUniversityContext context)
        {
            base.Seed(context);

            StudentsData.Seed(context);
            InstructorData.Seed(context);
            DepartmentData.Seed(context);
            CourseData.Seed(context);
            OfficeAssignmentData.Seed(context);
            EnrollmentData.Seed(context);
        }
Exemplo n.º 3
0
        public IActionResult Enroll(Student student)
        {
            EnrollmentData enrollment = _studentsDbService.Enroll(student);

            if (enrollment is null)
            {
                return(BadRequest());
            }
            else
            {
                return(StatusCode(201, enrollment));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult Show([FromBody] TokenModel token)
        {
            bool valido = false;

            valido = TokenData.ValidarToken(token.Token);

            if (valido == true)
            {
                string cad      = EnrollmentData.Enrollment(token.Token);
                var    consulta = PerfilData.Mostrar(cad);
                return(Ok(consulta));
            }
            return(NotFound());
        }
Exemplo n.º 5
0
        public IHttpActionResult ShowUser()
        {
            Credenciales cre    = new Credenciales();
            string       uss    = cre.getToken();
            bool         valido = false;

            valido = TokenData.ValidarToken(uss);
            if (valido == true)
            {
                string cad = EnrollmentData.UserAdmin(uss);

                var consulta = AdminData.MostrarUser(cad);
                return(Ok(consulta));
            }
            return(NotFound());
        }
Exemplo n.º 6
0
        private void OnDegreeChangeEx(WindowBase sender, UISelectionChangeEventArgs eventArgs)
        {
            try
            {
                EnrollmentDialogRowController controller;
                EnrollmentData enrollmentDataForSim = GetEnrollmentDataForSim(mSelectedSimDesc, out controller);
                if (enrollmentDataForSim != null)
                {
                    int num;
                    int num2;
                    FinancialAidtype aidtype;
                    CreditAwardtype  awardtype;
                    mHouseholdFunds -= enrollmentDataForSim.CostPerSim;
                    mHouseholdFunds -= enrollmentDataForSim.ScholarshipAmountPerSim;

                    AcademicDegreeStaticData staticElement = mDegreeCombo.EntryTags[(int)mDegreeCombo.CurrentSelection] as AcademicDegreeStaticData;

                    enrollmentDataForSim.AcademicDegreeName = (ulong)staticElement.AcademicDegreeName;
                    //enrollmentDataForSim.AcademicDegreeName = (ulong)(mDegreeCombo.CurrentSelection + 0x1L);

                    enrollmentDataForSim.CostPerSim              = UpdateFunds(enrollmentDataForSim.AcademicDegreeName, mSelectedSimDesc as SimDescription, out num2, out aidtype, out num, out awardtype);
                    enrollmentDataForSim.FinancialAidType        = aidtype;
                    enrollmentDataForSim.ScholarshipAmountPerSim = num2;
                    enrollmentDataForSim.CreditsAwardedPerSim    = num;
                    enrollmentDataForSim.CreditAwardType         = awardtype;
                    enrollmentDataForSim.CourseLoad              = this.mCourseLoad;
                    controller.mTextControlCost.Color            = (enrollmentDataForSim.CostPerSim < 0x0) ? RED : BLUE;
                    controller.Cost        = UIUtils.FormatMoney(Math.Abs(enrollmentDataForSim.CostPerSim));
                    controller.Scholarship = enrollmentDataForSim.ScholarshipAmountPerSim;
                    controller.AidType     = enrollmentDataForSim.FinancialAidType;

                    mDegreeDescription.Caption = Responder.Instance.LocalizationModel.LocalizeString(staticElement.DegreeDescKey, new object[0x0]);

                    UpdateCreditIconEx(enrollmentDataForSim.CreditsAwardedPerSim, enrollmentDataForSim.CreditAwardType, (AcademicDegreeNames)enrollmentDataForSim.AcademicDegreeName);
                    //UpdateCreditIcon(enrollmentDataForSim.CreditsAwardedPerSim, (int)enrollmentDataForSim.CreditAwardType, (int)enrollmentDataForSim.AcademicDegreeName);

                    UpdateDegreeProgressBar(mSelectedSimDesc, enrollmentDataForSim.AcademicDegreeName);
                }

                UpdateAcceptAvailability();
            }
            catch (Exception e)
            {
                Common.Exception("OnDegreeChangeEx", e);
            }
        }
Exemplo n.º 7
0
        public IHttpActionResult Days([FromBody] TokenModel token)
        {
            bool valido = false;

            valido = TokenData.ValidarToken(token.Token);
            Comps dates = new Comps();

            if (valido == true)
            {
                //EnrollmentData Mat = new EnrollmentData();
                string cad      = EnrollmentData.Enrollment(token.Token);
                var    consulta = LessonWeekData.Days(cad);
                return(Ok(consulta));
            }

            return(NotFound());
        }
Exemplo n.º 8
0
        public async Task <string> EnrollClientAsync(EnrollmentData data)
        {
            var service = new HttpRequestFactory();
            var url     = _configuration["EnrollClient:Url"];
            var isError = false;

            var request = new Models.AccionesAdhesionBancaAutomatica.AdherirClienteFisicoProductoBancaAutomaticaRequest
            {
                BGBAHeader = await _objectFactory.InstantiateFromJsonFile <Models.AccionesAdhesionBancaAutomatica.BGBAHeader>(_configuration["EnrollClient:BGBAHeader"]),
                Datos      = _mapper.Map <EnrollmentData, Models.AccionesAdhesionBancaAutomatica.AdherirClienteFisicoProductoBancaAutomaticaRequestDatos>(data)
            };

            try
            {
                var response = (await service.Post(url, new SoapJsonContent(request, _configuration["EnrollClient:Operation"]), _certificate)).SoapContentAsJsonType <Models.AccionesAdhesionBancaAutomatica.AdherirClienteFisicoProductoBancaAutomaticaResponse>();

                if (response.BGBAResultadoOperacion.Severidad == Models.AccionesAdhesionBancaAutomatica.severidad.OK)
                {
                    return(response.Datos.NumeroAdhesionClienteCanalesAlternativos.ToString());
                }

                throw new TechnicalException(response.BGBAResultadoOperacion.Descripcion, response.BGBAResultadoOperacion.Codigo);
            }
            catch (Exception e)
            {
                isError = true;

                if (e.GetType() == typeof(TechnicalException))
                {
                    throw;
                }

                throw new InvalidOperationException("Error al realizar el servicio.", e);
            }
            finally
            {
                this.Communicator_TraceHandler(this, new TraceEventArgs()
                {
                    ElapsedTime = service.ElapsedTime, URL = url, Request = service.Request, Response = service.Response, IsError = isError
                });
            }
        }
Exemplo n.º 9
0
        private void OnCourseLoadSliderChangedEx(WindowBase sender, UIValueChangedEventArgs eventArgs)
        {
            try
            {
                Slider slider = sender as Slider;
                if (slider != null)
                {
                    EnrollmentDialogRowController controller;
                    mCourseLoad = (uint)slider.Value;
                    EnrollmentData enrollmentDataForSim = GetEnrollmentDataForSim(mSelectedSimDesc, out controller);
                    if (enrollmentDataForSim != null)
                    {
                        int num;
                        int num2;
                        FinancialAidtype aidtype;
                        CreditAwardtype  awardtype;
                        mHouseholdFunds -= enrollmentDataForSim.CostPerSim;
                        mHouseholdFunds -= enrollmentDataForSim.ScholarshipAmountPerSim;
                        enrollmentDataForSim.CostPerSim              = UpdateFunds(enrollmentDataForSim.AcademicDegreeName, mSelectedSimDesc as SimDescription, out num2, out aidtype, out num, out awardtype);
                        enrollmentDataForSim.FinancialAidType        = aidtype;
                        enrollmentDataForSim.ScholarshipAmountPerSim = num2;
                        enrollmentDataForSim.CreditsAwardedPerSim    = num;
                        enrollmentDataForSim.CourseLoad              = mCourseLoad;
                        enrollmentDataForSim.CreditAwardType         = awardtype;
                        controller.mTextControlCost.Color            = (enrollmentDataForSim.CostPerSim < 0x0) ? RED : BLUE;
                        controller.Cost        = UIUtils.FormatMoney(Math.Abs(enrollmentDataForSim.CostPerSim));
                        controller.Scholarship = enrollmentDataForSim.ScholarshipAmountPerSim;
                        controller.AidType     = enrollmentDataForSim.FinancialAidType;

                        // Custom
                        UpdateCreditIconEx(enrollmentDataForSim.CreditsAwardedPerSim, enrollmentDataForSim.CreditAwardType, (AcademicDegreeNames)enrollmentDataForSim.AcademicDegreeName);

                        UpdateDegreeProgressBar(mSelectedSimDesc, enrollmentDataForSim.AcademicDegreeName);
                    }
                }
            }
            catch (Exception e)
            {
                Common.Exception("OnCourseLoadSliderChangedEx", e);
            }
        }
Exemplo n.º 10
0
        public async Task <string> EnrollAlphanumericAsync(EnrollmentData data)
        {
            var service = new HttpRequestFactory();
            var url     = _configuration["EnrollAlphanumeric:Url"];
            var isError = false;

            var request = new Models.AdministracionUsuarioHomebanking.CrearUsuarioRequest
            {
                BGBAHeader = await _objectFactory.InstantiateFromJsonFile <Models.AdministracionUsuarioHomebanking.BGBAHeader>(_configuration["EnrollAlphanumeric:BGBAHeader"]),
                Datos      = _mapper.Map <EnrollmentData, Models.AdministracionUsuarioHomebanking.CrearUsuarioRequestDatos>(data)
            };

            try
            {
                var response = (await service.Post(url, new SoapJsonContent(request, _configuration["EnrollAlphanumeric:Operation"]), _certificate)).SoapContentAsJsonType <Models.AdministracionUsuarioHomebanking.CrearUsuarioResponse>();
                if (response.BGBAResultadoOperacion.Severidad == Models.AdministracionUsuarioHomebanking.severidad.OK)
                {
                    return(response.BGBAResultadoOperacion.Codigo);
                }

                throw new TechnicalException(response.BGBAResultadoOperacion.Descripcion, response.BGBAResultadoOperacion.Codigo);
            }
            catch (Exception e)
            {
                isError = true;

                if (e.GetType() == typeof(TechnicalException))
                {
                    throw;
                }

                throw new InvalidOperationException("Error realizar el llamado al servicio.", e);
            }
            finally
            {
                this.Communicator_TraceHandler(this, new TraceEventArgs()
                {
                    ElapsedTime = service.ElapsedTime, URL = url, Request = service.Request, Response = service.Response, IsError = isError
                });
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            IList<AuthenticationTemplateData> templates = (from atd in (IEnumerable<AuthenticationTemplateData>)RepositoryFactory.AuthenticationTemplateRepository.GetAllAuthenticationTemplates()
                                                           where atd.AuthenticationUnitCode != "P1"
                                                           select atd).ToList();

            Random rndGroup = new Random();
            Random rndTemplate = new Random();
            Guid adminId = Guid.Empty;

            for (int i = 0; i < 100000; i++)
            {
                Console.WriteLine("Adding Identity " + i);
                IdentityData identity = new IdentityData()
                {
                    CountryCode = "US",
                    FirstName = "Scott" + i,
                    LastName = "Sickles" + i,
                    FullName = "Scott" + i + " Sickles" + i,
                    IdentityCode = i % 10 == 0 ? "E" : "C",
                    SourceId = i.ToString(),
                    GroupId = rndGroup.Next(26) + 1
                };
                identity.Uid = RepositoryFactory.IdentityRepository.Add(identity);
                Audit.AuditEvent(Audit.EventTypes.AddIdentity, string.Format("Identity {0} has been added.", identity.Uid), Guid.Empty);

                LoginData login1 = new LoginData()
                {
                    IdentityId = identity.Uid,
                    ApplicationCode = "T24",
                    LoginName = "AUTHOR",
                    Password = "******",
                    RoleCode = "T24USER",
                    T24Id = i.ToString()
                };
                login1.Id = RepositoryFactory.LoginRepository.Add(login1);
                Audit.AuditEvent(Audit.EventTypes.AddLogin, string.Format("Login {0} has been added for Identity {1}.", login1.Id, identity.Uid), Guid.Empty);

                LoginData login2 = new LoginData()
                {
                    IdentityId = identity.Uid,
                    ApplicationCode = "LA",
                    LoginName = "system",
                    Password = "******",
                    RoleCode = "LAUSER",
                    T24Id = i.ToString()
                };
                login2.Id = RepositoryFactory.LoginRepository.Add(login2);
                Audit.AuditEvent(Audit.EventTypes.AddLogin, string.Format("Login {0} has been added for Identity {1}.", login2.Id, identity.Uid), Guid.Empty);

                EnrollmentData enroll1 = new EnrollmentData()
                {
                    IdentityId = identity.Uid,
                    AdministratorId = adminId,
                    AuthenticationTypeCode = "FP"
                };
                enroll1.Uid = RepositoryFactory.EnrollmentRepository.Add(enroll1);
                Audit.AuditEvent(Audit.EventTypes.AddEnrollment, string.Format("Enrollment {0} has been added for Identity {1}.", enroll1.Uid, identity.Uid), Guid.Empty);
                //now add the templates to go along with the enrollment
                List<int> temps1 = new List<int>();
                for (int j = 0; j < 10; j++)
                {
                    int tempIndex;
                    do
                    {
                        tempIndex = rndTemplate.Next(templates.Count - 1);
                    } while (temps1.Contains(tempIndex));
                    temps1.Add(tempIndex);
                    AuthenticationTemplateData temp = new AuthenticationTemplateData()
                    {
                        AuthenticationUnitCode = templates[tempIndex].AuthenticationUnitCode,
                        EnrollmentId = enroll1.Uid,
                        Score = templates[tempIndex].Score,
                        Template = templates[tempIndex].Template
                    };
                    temp.Uid = RepositoryFactory.AuthenticationTemplateRepository.Add(temp);
                    Audit.AuditEvent(Audit.EventTypes.AddAuthenticationTemplate, string.Format("Authentication Template {0} has been added for Enrollment {1}.", temp.Uid, enroll1.Uid), Guid.Empty);
                }

                if (i % 5 == 0)
                {
                    EnrollmentData enroll2 = new EnrollmentData()
                    {
                        IdentityId = identity.Uid,
                        AdministratorId = adminId,
                        AuthenticationTypeCode = "FP"
                    };
                    enroll2.Uid = RepositoryFactory.EnrollmentRepository.Add(enroll2);
                    Audit.AuditEvent(Audit.EventTypes.AddEnrollment, string.Format("Enrollment {0} has been added for Identity {1}.", enroll2.Uid, identity.Uid), Guid.Empty);
                    //now add the templates to go along with the enrollment
                    List<int> temps2 = new List<int>();
                    for (int j = 0; j < 10; j++)
                    {
                        int tempIndex;
                        do
                        {
                            tempIndex = rndTemplate.Next(templates.Count - 1);
                        } while (temps2.Contains(tempIndex));
                        temps2.Add(tempIndex);
                        AuthenticationTemplateData temp = new AuthenticationTemplateData()
                        {
                            AuthenticationUnitCode = templates[tempIndex].AuthenticationUnitCode,
                            EnrollmentId = enroll2.Uid,
                            Score = templates[tempIndex].Score,
                            Template = templates[tempIndex].Template
                        };
                        temp.Uid = RepositoryFactory.AuthenticationTemplateRepository.Add(temp);
                        Audit.AuditEvent(Audit.EventTypes.AddAuthenticationTemplate, string.Format("Authentication Template {0} has been added for Enrollment {1}.", temp.Uid, enroll2.Uid), Guid.Empty);
                    }
                }

                //every fifth identity added becomes the enrollment officer for the next 5
                if (i % 5 == 0) adminId = identity.Uid;
            }
        }
Exemplo n.º 12
0
        private void UpdateSelection()
        {
            bool select = false;

            SimDescription sim = mSelectedSimDesc as SimDescription;

            if (sim != null)
            {
                select = true;

                if ((sim.ChildOrBelow) || (sim.IsPet))
                {
                    select = false;
                }
            }

            mDegreeCombo.Enabled    = select;
            mCourseLoadSldr.Enabled = select;

            EnrollmentDialogRowController controller;
            EnrollmentData enrollmentDataForSim = GetEnrollmentDataForSim(mSelectedSimDesc, out controller);

            if (enrollmentDataForSim != null)
            {
                if (!select)
                {
                    if (enrollmentDataForSim.CourseLoad != 0)
                    {
                        mCourseLoad = 0;

                        int num;
                        int num2;
                        FinancialAidtype aidtype;
                        CreditAwardtype  awardtype;
                        mHouseholdFunds -= enrollmentDataForSim.CostPerSim;
                        mHouseholdFunds -= enrollmentDataForSim.ScholarshipAmountPerSim;
                        enrollmentDataForSim.CostPerSim              = UpdateFunds(enrollmentDataForSim.AcademicDegreeName, mSelectedSimDesc as SimDescription, out num2, out aidtype, out num, out awardtype);
                        enrollmentDataForSim.FinancialAidType        = aidtype;
                        enrollmentDataForSim.ScholarshipAmountPerSim = num2;
                        enrollmentDataForSim.CreditsAwardedPerSim    = num;
                        enrollmentDataForSim.CourseLoad              = mCourseLoad;
                        enrollmentDataForSim.CreditAwardType         = awardtype;
                        controller.mTextControlCost.Color            = (enrollmentDataForSim.CostPerSim < 0) ? RED : BLUE;
                        controller.Cost        = UIUtils.FormatMoney(Math.Abs(enrollmentDataForSim.CostPerSim));
                        controller.Scholarship = enrollmentDataForSim.ScholarshipAmountPerSim;
                        controller.AidType     = enrollmentDataForSim.FinancialAidType;

                        UpdateCreditIconEx(enrollmentDataForSim.CreditsAwardedPerSim, enrollmentDataForSim.CreditAwardType, (AcademicDegreeNames)enrollmentDataForSim.AcademicDegreeName);
                        UpdateDegreeProgressBar(mSelectedSimDesc, enrollmentDataForSim.AcademicDegreeName);
                    }
                }
                else
                {
                    uint index = 0;
                    for (int i = 0; i < mDegreeCombo.ValueList.Count; i++)
                    {
                        AcademicDegreeStaticData data = mDegreeCombo.EntryTags[i] as AcademicDegreeStaticData;
                        if ((ulong)data.AcademicDegreeName == enrollmentDataForSim.AcademicDegreeName)
                        {
                            index = (uint)i;
                            break;
                        }
                    }

                    mDegreeCombo.SelectionChange -= OnDegreeChange;
                    mDegreeCombo.CurrentSelection = index;
                }
            }

            mDegreeCombo.SelectionChange -= OnDegreeChange;
            mDegreeCombo.SelectionChange += OnDegreeChangeEx;
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Cliente([FromBody] EnrollmentData data, [FromHeader] string sessionId = "")
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _enrollServices.TraceHandler += new BGBA.Models.N.Core.Trace.TraceEventHandler(delegate(object sender, BGBA.Models.N.Core.Trace.TraceEventArgs e)
                {
                    base.Communicator_TraceHandler(sender, e, sessionId);
                });

                var result = new Models.EnrollResult();

                if (string.IsNullOrEmpty(data.EnrollNumber))
                {
                    data.EncryptedPin = await _enrollServices.GetSCSCipherPasswordAsync(data.IdHost, data.Pin);

                    _logger.LogInformation($"Pin encrypted|sessionId:{sessionId}");

                    try
                    {
                        data.EnrollNumber = result.EnrollNumber = await _enrollServices.EnrollClientAsync(data);

                        result.EnrollState = Models.EnrollState.OK;
                        _logger.LogInformation($"Enroll client|sessionId:{sessionId}");
                    }
                    catch (TechnicalException e)
                    {
                        if (e.TechnicalCode == _enrollServices.ERROR_ALREDY_REGISTERED)
                        {
                            result.EnrollState = Models.EnrollState.ALREADY_ENROLL;
                        }
                        else if (e.TechnicalCode == _enrollServices.ERROR_PIN_SCS)
                        {
                            result.EnrollState = Models.EnrollState.INVALID_PIN;
                        }
                        else
                        {
                            throw;
                        }

                        return(new ObjectResult(result));
                    }
                }
                else
                {
                    result.EnrollNumber = data.EnrollNumber;
                }

                try
                {
                    await _enrollServices.EnrollAlphanumericAsync(data);

                    result.AlphanumericState = Models.AlphanumericState.OK;
                    _logger.LogInformation($"Enroll alphanumeric|sessionId:{sessionId}");
                }
                catch (TechnicalException e)
                {
                    if (e.TechnicalCode == _enrollServices.NOT_INFORMED)
                    {
                        result.AlphanumericState = Models.AlphanumericState.NOT_INFORMED;
                    }
                    else if (e.TechnicalCode == _enrollServices.CONSECUTIVE_CHARACTERS)
                    {
                        result.AlphanumericState = Models.AlphanumericState.CONSECUTIVE_CHARACTERS;
                    }
                    else if (e.TechnicalCode == _enrollServices.INCORRECT_CHARACTERS)
                    {
                        result.AlphanumericState = Models.AlphanumericState.INCORRECT_CHARACTERS;
                    }
                    else
                    {
                        throw;
                    }
                }

                return(new ObjectResult(result));
            }
            catch (System.Exception e)
            {
                _logger.LogError($"{e.ToString()}|sessionId:{sessionId}");
                return(new ObjectResult("Error al adherir cliente.")
                {
                    StatusCode = 500
                });
            }
        }
Exemplo n.º 14
0
        public EnrollmentData Enroll(Student student)
        {
            EnrollmentData enrollment = new EnrollmentData();

            /* Check if all the required data has been delivered */
            if (
                student.IndexNumber is null ||
                student.IndexNumber.Equals(string.Empty) ||
                student.FirstName is null ||
                student.FirstName.Equals(string.Empty) ||
                student.LastName is null ||
                student.LastName.Equals(string.Empty) ||
                student.BirthDate is null ||
                student.BirthDate.Equals(string.Empty) ||
                student.Studies is null ||
                student.Studies.Equals(string.Empty)
                )
            {
                return(null);
            }

            /* Connect to the database */
            using (var connection = new SqlConnection(CONNECTION_STRING))
            {
                using (var command = new SqlCommand())
                {
                    command.Connection = connection;

                    connection.Open();
                    var transaction = connection.BeginTransaction();
                    command.Transaction = transaction;

                    /* Check if provided studies exists */
                    command.CommandText = "SELECT * FROM Studies WHERE Name = @Name";
                    command.Parameters.AddWithValue("@Name", student.Studies);
                    var reader = command.ExecuteReader();
                    if (!reader.Read())
                    {
                        reader.Close();
                        transaction.Rollback();
                        return(null);
                    }
                    string idStudies = reader["IdStudy"].ToString();
                    reader.Close();

                    /* Check if index number is not occupied */
                    command.CommandText = "SELECT * FROM Student WHERE IndexNumber = @IndexNumber";
                    command.Parameters.AddWithValue("@IndexNumber", student.IndexNumber);
                    reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        reader.Close();
                        transaction.Rollback();
                        return(null);
                    }
                    reader.Close();

                    /* Check if enrollment for this studies already exists */
                    command.CommandText = "SELECT * FROM Enrollment WHERE Semester = 1 AND IdStudy = @IdStudy ORDER BY StartDate";
                    command.Parameters.AddWithValue("@IdStudy", idStudies);
                    reader = command.ExecuteReader();
                    if (!reader.Read())
                    {
                        reader.Close();

                        /* Add a new enrollment */
                        command.CommandText = "SELECT MAX(IdEnrollment) FROM Enrollment";
                        reader = command.ExecuteReader();

                        int idEnrollment = -1;
                        if (!reader.Read())
                        {
                            idEnrollment = 1;
                        }
                        else
                        {
                            idEnrollment = (int)reader["IdEnrollment"];
                        }
                        idEnrollment++;
                        reader.Close();

                        command.CommandText = "INSERT INTO Enrollment VALUES (@IdEnrollment, 1, @IdStudy, @StartDate)";
                        command.Parameters.AddWithValue("@IdEnrollment", idEnrollment);
                        command.Parameters.AddWithValue("@IdStudy", idStudies);
                        command.Parameters.AddWithValue("@StartDate", DateTime.Now.ToString("yyyy-MM-dd"));

                        reader = command.ExecuteReader();

                        command.Parameters.AddWithValue("@IdEnrollment", idEnrollment);
                        reader.Close();
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@IdEnrollment", reader["IdEnrollment"]);
                        reader.Close();
                    }

                    command.CommandText = "INSERT INTO Student VALUES (@IndexNumber, @FirstName, @LastName, @BirthDate, @IdEnrollment)";
                    command.Parameters.AddWithValue("@FirstName", student.FirstName);
                    command.Parameters.AddWithValue("@LastName", student.LastName);
                    command.Parameters.AddWithValue("@BirthDate", student.BirthDate);

                    reader = command.ExecuteReader();
                    reader.Close();
                    transaction.Commit();

                    enrollment.FirstName = student.FirstName;
                    enrollment.LastName  = student.LastName;
                    enrollment.Semester  = 1.ToString();
                    enrollment.Studies   = student.Studies;
                }
            }

            return(enrollment);
        }