Exemple #1
0
        /// <summary>
        /// Get organization with id.
        /// </summary>
        /// <param name="organizationId">organization id</param>
        /// <returns>organization or null if the organization wasn't found with given organization id</returns>
        public SourceOrganizationEntity GetOrganization(int organizationId)
        {
            SourceOrganizationEntity entity = null;

            using (var command = this._dbContext.Database.GetDbConnection().CreateCommand())
            {
                command.CommandTimeout = 15;
                command.CommandType    = System.Data.CommandType.Text;
                command.CommandText    = "select jsonobject from organization_entity where id = @orgid";

                var param = command.CreateParameter();
                param.DbType        = System.Data.DbType.Int64;
                param.Direction     = System.Data.ParameterDirection.Input;
                param.ParameterName = "@orgid";
                param.Value         = organizationId;

                command.Parameters.Add(param);

                SourceRepository.EnsureConnectionOpen(command);

                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        if (reader.Read())
                        {
                            entity = JsonHelper.Deserialize <SourceOrganizationEntity>(reader.GetString(0) as string);
                        }
                        else
                        {
                            _logger.LogError($"Failed to read organization with id '{organizationId}' from result.");
                        }
                    }
                    else
                    {
                        _logger.LogWarning($"No organizations found from source database with id: '{organizationId}'.");
                    }
                }

                command.Connection.Close();
            }

            return(entity);
        }
Exemple #2
0
        /// <summary>
        /// Get all organizations.
        /// </summary>
        /// <returns>list of organizations</returns>
        public List <SourceOrganizationEntity> GetOrganizations()
        {
            List <SourceOrganizationEntity> orgs = new List <SourceOrganizationEntity>(10);

            using (var command = this._dbContext.Database.GetDbConnection().CreateCommand())
            {
                command.CommandTimeout = 15;
                command.CommandType    = System.Data.CommandType.Text;
                command.CommandText    = "select jsonobject from organization_entity";

                SourceRepository.EnsureConnectionOpen(command);

                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            SourceOrganizationEntity entity = JsonHelper.Deserialize <SourceOrganizationEntity>(reader.GetString(0) as string);

                            if (entity != null)
                            {
                                orgs.Add(entity);
                            }
                        }
                    }
                    else
                    {
                        _logger.LogWarning("No organizations found from source database.");
                    }
                }

                command.Connection.Close();
            }

            return(orgs);
        }