Ejemplo n.º 1
0
        public async Task Add(UploadFileHandleRecord record)
        {
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _fileManagementConnectionFactory.CreateAllForUploadFileHandle(), async (conn, transaction) =>
            {
                //新增
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }
                await using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                })
                {
                    SqlParameter parameter;
                    if (record.ID == Guid.Empty)
                    {
                        command.CommandText = @"
                                               insert into [UploadFileHandleRecord]
                                                (
	                                                  [id]
                                                      ,[UploadFileId]
                                                      ,[ConfigurationName]
                                                      ,[Error]
                                                      ,[Status]
                                                      ,[UploadFileRegardingType]
                                                      ,[UploadFileRegardingKey]
                                                      ,[ExtensionInfo]
                                                      ,[ResultInfo]
                                                      ,[createtime]
                                                      ,[modifytime]
                                                 )
                                                 values
                                                 (
	                                                 default
	                                                 ,@UploadFileId
                                                     ,@ConfigurationName
                                                     ,@Error
                                                     ,@Status
                                                     ,@UploadFileRegardingType
                                                     ,@UploadFileRegardingKey
                                                     ,@ExtensionInfo
                                                     ,@ResultInfo
	                                                 ,GETUTCDATE()
	                                                 ,GETUTCDATE()
                                                 );
                                                select @newid =[id] from UploadFileHandleRecord where [sequence] = SCOPE_IDENTITY()";
                        parameter           = new SqlParameter("@newid", SqlDbType.UniqueIdentifier)
                        {
                            Direction = ParameterDirection.Output
                        };
                        command.Parameters.Add(parameter);
                    }
                    else
                    {
                        command.CommandText = @"insert into[UploadFileHandleRecord]
                                                (

                                                      [id]
                                                      ,[UploadFileId]
                                                      ,[ConfigurationName]
                                                      ,[Error]
                                                      ,[Status]
                                                      ,[UploadFileRegardingType]
                                                      ,[UploadFileRegardingKey]
                                                      ,[ExtensionInfo]
                                                      ,[ResultInfo]
                                                      ,[createtime]
                                                      ,[modifytime]
                                                 )
                                                 values
                                                 (
                                                     @id
                                                     , @UploadFileId
                                                     , @ConfigurationName
                                                     , @Error
                                                     , @Status
                                                     , @UploadFileRegardingType
                                                     , @UploadFileRegardingKey
                                                     , @ExtensionInfo
                                                     , @ResultInfo
                                                     , GETUTCDATE()
                                                     , GETUTCDATE()
                                                 )";

                        parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                        {
                            Value = record.ID
                        };
                        command.Parameters.Add(parameter);
                    }

                    parameter = new SqlParameter("@UploadFileId", SqlDbType.UniqueIdentifier)
                    {
                        Value = record.UploadFileId
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@ConfigurationName", SqlDbType.NVarChar, 2000)
                    {
                        Value = record.ConfigurationName
                    };
                    command.Parameters.Add(parameter);
                    parameter = new SqlParameter("@Error", SqlDbType.NVarChar, -1)
                    {
                        Value = (object)record.Error ?? DBNull.Value
                    };
                    command.Parameters.Add(parameter);
                    parameter = new SqlParameter("@Status", SqlDbType.Int)
                    {
                        Value = record.Status
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@UploadFileRegardingType", SqlDbType.NVarChar, 500)
                    {
                        Value = record.UploadFileRegardingType
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@UploadFileRegardingKey", SqlDbType.NVarChar, 500)
                    {
                        Value = record.UploadFileRegardingKey
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@ExtensionInfo", SqlDbType.NVarChar, 2000)
                    {
                        Value = (object)record.ExtensionInfo ?? DBNull.Value
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@ResultInfo", SqlDbType.NVarChar, 2000)
                    {
                        Value = (object)record.ResultInfo ?? DBNull.Value
                    };
                    command.Parameters.Add(parameter);


                    await command.PrepareAsync();


                    await command.ExecuteNonQueryAsync();


                    //如果用户未赋值ID则创建成功后返回ID
                    if (record.ID == Guid.Empty)
                    {
                        record.ID = (Guid)command.Parameters["@newid"].Value;
                    }
                    ;
                }
            });
        }
Ejemplo n.º 2
0
        public async Task <UploadFileHandleConfiguration> QueryById(Guid id)
        {
            UploadFileHandleConfiguration conf = null;

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _fileManagementConnectionFactory.CreateAllForUploadFileHandle(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }
                await using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"SELECT {0} FROM UploadFileHandleConfiguration WHERE id=@id", StoreHelper.GetUploadFileHandleConfigurationFields(string.Empty)),
                    Transaction = sqlTran,
                })
                {
                    var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                    {
                        Value = id
                    };
                    command.Parameters.Add(parameter);
                    await command.PrepareAsync();
                    SqlDataReader reader = null;

                    await using (reader = await command.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            conf = new UploadFileHandleConfiguration();

                            StoreHelper.SetUploadFileHandleConfigurationFields(conf, reader, string.Empty);
                        }
                        await reader.CloseAsync();
                    }
                }
            });

            return(conf);
        }