public async Task <UploadFileHandleConfiguration> QueryByNameStatus(string name, int status) { 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 [name]=@name and [status] = @status", StoreHelper.GetUploadFileHandleConfigurationFields(string.Empty)), Transaction = sqlTran, }) { var parameter = new SqlParameter("@name", SqlDbType.NVarChar, 100) { Value = name }; command.Parameters.Add(parameter); parameter = new SqlParameter("@status", SqlDbType.Int) { Value = status }; 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); }
/// <summary> /// uploadFileHandleConfiguration数据赋值 /// </summary> /// <param name="uploadFileHandleConfiguration"></param> /// <param name="reader"></param> /// <param name="prefix"></param> public static void SetUploadFileHandleConfigurationFields(UploadFileHandleConfiguration uploadFileHandleConfiguration, DbDataReader reader, string prefix) { if (reader[string.Format("{0}id", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.ID = (Guid)reader[string.Format("{0}id", prefix)]; } if (reader[string.Format("{0}name", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.Name = reader[string.Format("{0}name", prefix)].ToString(); } if (reader[string.Format("{0}AllowSuffixs", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.AllowSuffixs = reader[string.Format("{0}AllowSuffixs", prefix)].ToString().Split(','); } if (reader[string.Format("{0}Configuration", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.Configuration = reader[string.Format("{0}Configuration", prefix)].ToString(); } if (reader[string.Format("{0}Description", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.Description = reader[string.Format("{0}Description", prefix)].ToString(); } if (reader[string.Format("{0}status", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.Status = int.Parse(reader[string.Format("{0}status", prefix)].ToString()); } if (reader[string.Format("{0}createtime", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.CreateTime = (DateTime)reader[string.Format("{0}createtime", prefix)]; } if (reader[string.Format("{0}modifytime", prefix)] != DBNull.Value) { uploadFileHandleConfiguration.ModifyTime = (DateTime)reader[string.Format("{0}modifytime", prefix)]; } }