Exemple #1
0
 /// <summary>
 /// Fills object from a SqlClient Data Reader
 /// </summary>
 /// <remarks></remarks>
 public void Fill(Microsoft.Data.SqlClient.SqlDataReader dr)
 {
     _ID          = (int)dr[db_ID];
     _Name        = (string)dr[db_Name];
     _IndexNumber = (int)dr[db_IndexNumber];
     _Professor   = (int)dr[db_Professor];
 }
Exemple #2
0
        public async Task UpsertStatuses(IReadOnlyCollection <ResourceSearchParameterStatus> statuses, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(statuses, nameof(statuses));

            if (!statuses.Any())
            {
                return;
            }

            if (_schemaInformation.Current < SchemaVersionConstants.SearchParameterStatusSchemaVersion)
            {
                throw new BadRequestException(Resources.SchemaVersionNeedsToBeUpgraded);
            }

            using (IScoped <SqlConnectionWrapperFactory> scopedSqlConnectionWrapperFactory = _scopedSqlConnectionWrapperFactory())
                using (SqlConnectionWrapper sqlConnectionWrapper = await scopedSqlConnectionWrapperFactory.Value.ObtainSqlConnectionWrapperAsync(cancellationToken, true))
                    using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand())
                    {
                        VLatest.UpsertSearchParams.PopulateCommand(sqlCommandWrapper, _updateSearchParamsTvpGenerator.Generate(statuses.ToList()));

                        using (SqlDataReader sqlDataReader = await sqlCommandWrapper.ExecuteReaderAsync(CommandBehavior.SequentialAccess, cancellationToken))
                        {
                            while (await sqlDataReader.ReadAsync(cancellationToken))
                            {
                                // The upsert procedure returns the search parameters that were new.
                                (short searchParamId, string searchParamUri) = sqlDataReader.ReadRow(VLatest.SearchParam.SearchParamId, VLatest.SearchParam.Uri);

                                // Add the new search parameters to the FHIR model dictionary.
                                _fhirModel.TryAddSearchParamIdToUriMapping(searchParamUri, searchParamId);
                            }
                        }
                    }
        }
        // TODO: Make cancellation token an input.
        public async Task <IReadOnlyCollection <ResourceSearchParameterStatus> > GetSearchParameterStatuses()
        {
            // If the search parameter table in SQL does not yet contain status columns
            if (_schemaInformation.Current < SchemaVersionConstants.SearchParameterStatusSchemaVersion)
            {
                // Get status information from file.
                return(await _filebasedSearchParameterStatusDataStore.GetSearchParameterStatuses());
            }

            using (IScoped <SqlConnectionWrapperFactory> scopedSqlConnectionWrapperFactory = _scopedSqlConnectionWrapperFactory())
                using (SqlConnectionWrapper sqlConnectionWrapper = await scopedSqlConnectionWrapperFactory.Value.ObtainSqlConnectionWrapperAsync(CancellationToken.None, true))
                    using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand())
                    {
                        VLatest.GetSearchParamStatuses.PopulateCommand(sqlCommandWrapper);

                        var parameterStatuses = new List <ResourceSearchParameterStatus>();

                        using (SqlDataReader sqlDataReader = await sqlCommandWrapper.ExecuteReaderAsync(CommandBehavior.SequentialAccess, CancellationToken.None))
                        {
                            while (await sqlDataReader.ReadAsync())
                            {
                                (string uri, string stringStatus, DateTimeOffset? lastUpdated, bool?isPartiallySupported) = sqlDataReader.ReadRow(
                                    VLatest.SearchParam.Uri,
                                    VLatest.SearchParam.Status,
                                    VLatest.SearchParam.LastUpdated,
                                    VLatest.SearchParam.IsPartiallySupported);

                                if (string.IsNullOrEmpty(stringStatus) || lastUpdated == null || isPartiallySupported == null)
                                {
                                    // These columns are nullable because they are added to dbo.SearchParam in a later schema version.
                                    // They should be populated as soon as they are added to the table and should never be null.
                                    throw new NullReferenceException(Resources.SearchParameterStatusShouldNotBeNull);
                                }

                                var status = Enum.Parse <SearchParameterStatus>(stringStatus, true);

                                var resourceSearchParameterStatus = new ResourceSearchParameterStatus()
                                {
                                    Uri    = new Uri(uri),
                                    Status = status,
                                    IsPartiallySupported = (bool)isPartiallySupported,
                                    LastUpdated          = (DateTimeOffset)lastUpdated,
                                };

                                if (SqlServerSortingValidator.SupportedParameterUris.Contains(resourceSearchParameterStatus.Uri))
                                {
                                    resourceSearchParameterStatus.SortStatus = SortParameterStatus.Enabled;
                                }
                                else
                                {
                                    resourceSearchParameterStatus.SortStatus = SortParameterStatus.Supported;
                                }

                                parameterStatuses.Add(resourceSearchParameterStatus);
                            }
                        }

                        return(parameterStatuses);
                    }
        }
 public virtual bool Fill(Microsoft.Data.SqlClient.SqlDataReader reader, bool closeReader)
 {
     try {
         if ((reader.Read() == false))
         {
             reader.Close();
             return(false);
         }
         else
         {
             if ((reader["column_name"].Equals(System.DBNull.Value) == false))
             {
                 this.ColumnName = ((string)(System.Convert.ChangeType(reader["column_name"], typeof(string))));
             }
             if ((reader["data_type"].Equals(System.DBNull.Value) == false))
             {
                 this.DataType = ((string)(System.Convert.ChangeType(reader["data_type"], typeof(string))));
             }
             if ((reader["character_maximum_length"].Equals(System.DBNull.Value) == false))
             {
                 this.CharMaximum = ((int)(System.Convert.ChangeType(reader["character_maximum_length"], typeof(int))));
             }
             return(true);
         }
     }
     catch (System.Exception ex) {
         throw new System.ApplicationException("Error in the Auto-Generated: ColumnInfo.Fill(SqlDataReader) Method", ex);
     }
     finally {
         if ((closeReader == true))
         {
             reader.Close();
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Fills object from a SqlClient Data Reader
 /// </summary>
 /// <remarks></remarks>
 public void Fill(Microsoft.Data.SqlClient.SqlDataReader dr)
 {
     _ID        = (int)dr[db_ID];
     _FirstName = (string)dr[db_FirstName];
     _LastName  = (string)dr[db_LastName];
     _Office    = (int)dr[db_Office];
 }
        public async Task <IActionResult> PromoteStudents(EnrStud input)
        {
            SqlConnection conn = new SqlConnection(_connectionString);
            SqlCommand    com  = new SqlCommand();

            com.Connection  = conn;
            com.CommandText =
                @"select 
                        e.IdEnrollment, e.Semester, e.StartDate, s.IdStudy, s.Name
                      from Enrollment e
                        left join Studies s on s.IdStudy = e.IdStudy
                      where 
                        s.Name = @studyName
                        and e.Semester = @semester";

            com.Parameters.AddWithValue("studyName", input.Studies);
            com.Parameters.AddWithValue("semester", input.Semester);

            conn.Open();
            SqlDataReader dataReader = await com.ExecuteReaderAsync();

            await dataReader.ReadAsync();

            Enrollment enr = new Enrollment
            {
                IdEnrollment = int.Parse(dataReader["IdEnrollment"].ToString()),
                Semester     = int.Parse(dataReader["Semester"].ToString()),
                StartDate    = DateTime.Parse(dataReader["StartDate"].ToString()),
                Study        = new Study
                {
                    IdStudy = int.Parse(dataReader["IdStudy"].ToString()),
                    Name    = dataReader["Name"].ToString(),
                }
            };


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

            conn = new SqlConnection(_connectionString);
            com  = new SqlCommand();

            com.Connection  = conn;
            com.CommandType = System.Data.CommandType.StoredProcedure;
            com.CommandText = "PromoteStudents";

            com.Parameters.AddWithValue("studies", input.Studies);
            com.Parameters.AddWithValue("semester", input.Semester);

            conn.Open();
            await com.ExecuteNonQueryAsync();



            return(StatusCode(200));
        }
 /// <summary>
 /// Fills object from a SqlClient Data Reader
 /// </summary>
 /// <remarks></remarks>
 public void Fill(Microsoft.Data.SqlClient.SqlDataReader dr)
 {
     _ID            = (int)dr[db_ID];
     _FirstName     = (string)dr[db_FirstName];
     _LastName      = (string)dr[db_LastName];
     _Age           = (int)dr[db_Age];
     _NickName      = (string)dr[db_NickName];
     _FavoriteColor = (string)dr[db_FavoriteColor];
 }
 public virtual bool Fill(Microsoft.Data.SqlClient.SqlDataReader reader, bool closeReader)
 {
     try {
         if ((reader.Read() == false))
         {
             reader.Close();
             return(false);
         }
         else
         {
             if ((reader["ScriptFileName"].Equals(System.DBNull.Value) == false))
             {
                 this.ScriptFileName = ((string)(System.Convert.ChangeType(reader["ScriptFileName"], typeof(string))));
             }
             if ((reader["ScriptId"].Equals(System.DBNull.Value) == false))
             {
                 this.ScriptId = new System.Guid(reader["ScriptId"].ToString());
             }
             if ((reader["Sequence"].Equals(System.DBNull.Value) == false))
             {
                 this.Sequence = ((int)(System.Convert.ChangeType(reader["Sequence"], typeof(int))));
             }
             if ((reader["ScriptText"].Equals(System.DBNull.Value) == false))
             {
                 this.ScriptText = ((string)(System.Convert.ChangeType(reader["ScriptText"], typeof(string))));
             }
             if ((reader["Database"].Equals(System.DBNull.Value) == false))
             {
                 this.Database = ((string)(System.Convert.ChangeType(reader["Database"], typeof(string))));
             }
             if ((reader["Tag"].Equals(System.DBNull.Value) == false))
             {
                 this.Tag = ((string)(System.Convert.ChangeType(reader["Tag"], typeof(string))));
             }
             return(true);
         }
     }
     catch (System.Exception ex) {
         throw new System.ApplicationException("Error in the Auto-Generated: RebuilderData.Fill(SqlDataReader) Method", ex);
     }
     finally {
         if ((closeReader == true))
         {
             reader.Close();
         }
     }
 }
Exemple #9
0
 public virtual bool Fill(Microsoft.Data.SqlClient.SqlDataReader reader, bool closeReader)
 {
     try {
         if ((reader.Read() == false))
         {
             reader.Close();
             return(false);
         }
         else
         {
             if ((reader["ObjectName"].Equals(System.DBNull.Value) == false))
             {
                 this.ObjectName = ((string)(System.Convert.ChangeType(reader["ObjectName"], typeof(string))));
             }
             if ((reader["ObjectType"].Equals(System.DBNull.Value) == false))
             {
                 this.ObjectType = ((string)(System.Convert.ChangeType(reader["ObjectType"], typeof(string))));
             }
             if ((reader["CreateDate"].Equals(System.DBNull.Value) == false))
             {
                 this.CreateDate = ((System.DateTime)(System.Convert.ChangeType(reader["CreateDate"], typeof(System.DateTime))));
             }
             if ((reader["AlteredDate"].Equals(System.DBNull.Value) == false))
             {
                 this.AlteredDate = ((System.DateTime)(System.Convert.ChangeType(reader["AlteredDate"], typeof(System.DateTime))));
             }
             if ((reader["SchemaOwner"].Equals(System.DBNull.Value) == false))
             {
                 this.SchemaOwner = ((string)(System.Convert.ChangeType(reader["SchemaOwner"], typeof(string))));
             }
             return(true);
         }
     }
     catch (System.Exception ex) {
         throw new System.ApplicationException("Error in the Auto-Generated: ObjectData.Fill(SqlDataReader) Method", ex);
     }
     finally {
         if ((closeReader == true))
         {
             reader.Close();
         }
     }
 }
 public virtual bool Fill(Microsoft.Data.SqlClient.SqlDataReader reader, bool closeReader)
 {
     try {
         if ((reader.Read() == false))
         {
             reader.Close();
             return(false);
         }
         else
         {
             if ((reader["BuildFileName"].Equals(System.DBNull.Value) == false))
             {
                 this.BuildFileName = ((string)(System.Convert.ChangeType(reader["BuildFileName"], typeof(string))));
             }
             if ((reader["ScriptCount"].Equals(System.DBNull.Value) == false))
             {
                 this.ScriptCount = ((int)(System.Convert.ChangeType(reader["ScriptCount"], typeof(int))));
             }
             if ((reader["commitDate"].Equals(System.DBNull.Value) == false))
             {
                 this.CommitDate = ((System.DateTime)(System.Convert.ChangeType(reader["commitDate"], typeof(System.DateTime))));
             }
             if ((reader["database"].Equals(System.DBNull.Value) == false))
             {
                 this.Database = ((string)(System.Convert.ChangeType(reader["database"], typeof(string))));
             }
             return(true);
         }
     }
     catch (System.Exception ex) {
         throw new System.ApplicationException("Error in the Auto-Generated: CommittedBuildData.Fill(SqlDataReader) Method", ex);
     }
     finally {
         if ((closeReader == true))
         {
             reader.Close();
         }
     }
 }
Exemple #11
0
 internal Course(Microsoft.Data.SqlClient.SqlDataReader dr)
 {
     Fill(dr);
 }
Exemple #12
0
        public async Task <IReadOnlyCollection <ResourceSearchParameterStatus> > GetSearchParameterStatuses(CancellationToken cancellationToken)
        {
            // If the search parameter table in SQL does not yet contain status columns
            if (_schemaInformation.Current < SchemaVersionConstants.SearchParameterStatusSchemaVersion)
            {
                // Get status information from file.
                return(await _filebasedSearchParameterStatusDataStore.GetSearchParameterStatuses(cancellationToken));
            }

            using (IScoped <SqlConnectionWrapperFactory> scopedSqlConnectionWrapperFactory = _scopedSqlConnectionWrapperFactory())
                using (SqlConnectionWrapper sqlConnectionWrapper = await scopedSqlConnectionWrapperFactory.Value.ObtainSqlConnectionWrapperAsync(cancellationToken, true))
                    using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand())
                    {
                        VLatest.GetSearchParamStatuses.PopulateCommand(sqlCommandWrapper);

                        var parameterStatuses = new List <ResourceSearchParameterStatus>();

                        using (SqlDataReader sqlDataReader = await sqlCommandWrapper.ExecuteReaderAsync(CommandBehavior.SequentialAccess, cancellationToken))
                        {
                            while (await sqlDataReader.ReadAsync(cancellationToken))
                            {
                                short          id;
                                string         uri;
                                string         stringStatus;
                                DateTimeOffset?lastUpdated;
                                bool?          isPartiallySupported;

                                ResourceSearchParameterStatus resourceSearchParameterStatus;

                                if (_schemaInformation.Current >= SchemaVersionConstants.SearchParameterSynchronizationVersion)
                                {
                                    (id, uri, stringStatus, lastUpdated, isPartiallySupported) = sqlDataReader.ReadRow(
                                        VLatest.SearchParam.SearchParamId,
                                        VLatest.SearchParam.Uri,
                                        VLatest.SearchParam.Status,
                                        VLatest.SearchParam.LastUpdated,
                                        VLatest.SearchParam.IsPartiallySupported);

                                    if (string.IsNullOrEmpty(stringStatus) || lastUpdated == null || isPartiallySupported == null)
                                    {
                                        // These columns are nullable because they are added to dbo.SearchParam in a later schema version.
                                        // They should be populated as soon as they are added to the table and should never be null.
                                        throw new SearchParameterNotSupportedException(Resources.SearchParameterStatusShouldNotBeNull);
                                    }

                                    var status = Enum.Parse <SearchParameterStatus>(stringStatus, true);

                                    resourceSearchParameterStatus = new SqlServerResourceSearchParameterStatus
                                    {
                                        Id     = id,
                                        Uri    = new Uri(uri),
                                        Status = status,
                                        IsPartiallySupported = (bool)isPartiallySupported,
                                        LastUpdated          = (DateTimeOffset)lastUpdated,
                                    };
                                }
                                else
                                {
                                    (uri, stringStatus, lastUpdated, isPartiallySupported) = sqlDataReader.ReadRow(
                                        VLatest.SearchParam.Uri,
                                        VLatest.SearchParam.Status,
                                        VLatest.SearchParam.LastUpdated,
                                        VLatest.SearchParam.IsPartiallySupported);

                                    if (string.IsNullOrEmpty(stringStatus) || lastUpdated == null || isPartiallySupported == null)
                                    {
                                        // These columns are nullable because they are added to dbo.SearchParam in a later schema version.
                                        // They should be populated as soon as they are added to the table and should never be null.
                                        throw new SearchParameterNotSupportedException(Resources.SearchParameterStatusShouldNotBeNull);
                                    }

                                    var status = Enum.Parse <SearchParameterStatus>(stringStatus, true);

                                    resourceSearchParameterStatus = new ResourceSearchParameterStatus
                                    {
                                        Uri    = new Uri(uri),
                                        Status = status,
                                        IsPartiallySupported = (bool)isPartiallySupported,
                                        LastUpdated          = (DateTimeOffset)lastUpdated,
                                    };
                                }

                                if (_schemaInformation.Current >= SchemaVersionConstants.AddMinMaxForDateAndStringSearchParamVersion)
                                {
                                    // For schema versions starting from AddMinMaxForDateAndStringSearchParamVersion we will check
                                    // whether the corresponding type of the search parameter is supported.
                                    SearchParameterInfo paramInfo = null;
                                    try
                                    {
                                        paramInfo = _searchParameterDefinitionManager.GetSearchParameter(resourceSearchParameterStatus.Uri.OriginalString);
                                    }
                                    catch (SearchParameterNotSupportedException)
                                    {
                                    }

                                    if (paramInfo != null && SqlServerSortingValidator.SupportedSortParamTypes.Contains(paramInfo.Type))
                                    {
                                        resourceSearchParameterStatus.SortStatus = SortParameterStatus.Enabled;
                                    }
                                    else
                                    {
                                        resourceSearchParameterStatus.SortStatus = SortParameterStatus.Disabled;
                                    }
                                }
                                else
                                {
                                    if (_sortingValidator.SupportedParameterUris.Contains(resourceSearchParameterStatus.Uri))
                                    {
                                        resourceSearchParameterStatus.SortStatus = SortParameterStatus.Enabled;
                                    }
                                    else
                                    {
                                        resourceSearchParameterStatus.SortStatus = SortParameterStatus.Disabled;
                                    }
                                }

                                parameterStatuses.Add(resourceSearchParameterStatus);
                            }
                        }

                        return(parameterStatuses);
                    }
        }
Exemple #13
0
 internal Instructor(Microsoft.Data.SqlClient.SqlDataReader dr)
 {
     Fill(dr);
 }
        public async Task <IActionResult> registerStudent(StdEnr input)
        {
            SqlConnection conn = new SqlConnection(_connectionString);
            SqlCommand    com  = new SqlCommand();
            Study         study;

            {
                com.Connection  = conn;
                com.CommandText = "select IdStudy, Name from Studies where Name = @name";

                com.Parameters.AddWithValue("name", input.Studies);

                conn.Open();

                try
                {
                    SqlDataReader dataReader = await com.ExecuteReaderAsync();

                    await dataReader.ReadAsync();

                    study = new Study
                    {
                        IdStudy = int.Parse(dataReader["IdStudy"].ToString()),
                        Name    = dataReader["Name"].ToString()
                    };
                    if (study == null)
                    {
                        return(BadRequest());
                    }
                }
                catch
                {
                    return(null);
                }
            }
            conn = new SqlConnection(_connectionString);
            com  = new SqlCommand();

            conn.Open();
            SqlTransaction transaction = conn.BeginTransaction();

            com.Connection  = conn;
            com.Transaction = transaction;
            com.CommandText =
                @"declare @enrollmentId int
                      select
                          @enrollmentId = e.IdEnrollment
                      from Enrollment e
                          left join Studies s on e.IdStudy = s.IdStudy
                      where e.IdStudy = @studyId and e.Semester = 1
                      
                      if @enrollmentId is null
                      begin

                          select @enrollmentId = max(IdEnrollment) + 1 from Enrollment
                          insert into Enrollment values (@enrollmentId, 1, @studyId, getdate());

                      end

                      insert into Student values (@index, @firstName, @lastName, @birthDate, @enrollmentId)";

            com.Parameters.AddWithValue("studyId", study.IdStudy);
            com.Parameters.AddWithValue("index", input.IndexNumber);
            com.Parameters.AddWithValue("firstName", input.FirstName);
            com.Parameters.AddWithValue("lastName", input.LastName);
            com.Parameters.AddWithValue("birthDate", input.BirthDate);

            try
            {
                await com.ExecuteNonQueryAsync();

                await transaction.CommitAsync();
            }
            catch (Exception e)
            {
                await transaction.RollbackAsync();
            }

            return(StatusCode(200));
        }
 internal Student(Microsoft.Data.SqlClient.SqlDataReader dr)
 {
     Fill(dr);
 }
Exemple #16
0
 /// <summary>
 ///     ''' This function is called by the Security DAL to load this object from the database
 ///     ''' </summary>
 public abstract void Fill(Microsoft.Data.SqlClient.SqlDataReader dr);