本文整理汇总了C#中IQuery.ProjectMinimalQueryAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IQuery.ProjectMinimalQueryAsync方法的具体用法?C# IQuery.ProjectMinimalQueryAsync怎么用?C# IQuery.ProjectMinimalQueryAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQuery
的用法示例。
在下文中一共展示了IQuery.ProjectMinimalQueryAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HistoricalModule
public HistoricalModule(IQuery queries, ISoeService soeService)
: base("/historical/project/{id:int}")
{
Put["/create-related-data", true] = async (_, ctx) =>
{
var id = int.Parse(_.id);
var ten = TimeSpan.FromSeconds(600);
var db = await queries.OpenConnection();
using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, ten, TransactionScopeAsyncFlowOption.Enabled))
using (var connection = db.Connection)
{
if (!db.Open)
{
return Negotiate.WithReasonPhrase("Database Error")
.WithStatusCode(HttpStatusCode.InternalServerError)
.WithModel("Unable to connect to the database.");
}
var projects = await queries.ProjectMinimalQueryAsync(connection, new {id = (int) id});
var project = projects.FirstOrDefault();
// make sure project id is valid
if (project == null)
{
return Negotiate.WithReasonPhrase("Project not found")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("Project not found.");
}
const string geometryQuery =
"SELECT [Shape] shape, [FeatureId], [TypeDescription] category FROM {0} WHERE [Project_ID] = @id";
foreach (var table in new[] {"POINT", "LINE", "POLY"})
{
var query = string.Format(geometryQuery, table);
var features = await connection.QueryAsync<SpatialFeatureSimple>(query, new
{
id = (int) id
});
foreach (var feature in features)
{
var soeAreaAndLengthResponse = await soeService.QueryAreasAndLengthsAsync(feature.Shape);
// handle error from soe
if (!soeAreaAndLengthResponse.IsSuccessful)
{
return Negotiate.WithReasonPhrase(soeAreaAndLengthResponse.Error.Message)
.WithStatusCode(HttpStatusCode.InternalServerError)
.WithModel(soeAreaAndLengthResponse.Error.Message);
}
var size = soeAreaAndLengthResponse.Result.Size;
if (table == "POLY")
{
await connection.ExecuteAsync("UPDATE [dbo].[POLY]" +
"SET [AreaSqMeters] = @size " +
"WHERE [FeatureID] = @featureId", new
{
size,
featureId = feature.FeatureId
});
}
else if (table == "LINE")
{
await connection.ExecuteAsync("UPDATE [dbo].[LINE]" +
"SET [LengthLnMeters] = @size " +
"WHERE [FeatureID] = @featureId", new
{
size,
featureId = feature.FeatureId
});
}
var soeResponse = await soeService.QueryIntersectionsAsync(feature.Shape, feature.Category);
// handle error from soe
if (!soeResponse.IsSuccessful)
{
return Negotiate.WithReasonPhrase(soeResponse.Error.Message)
.WithStatusCode(HttpStatusCode.InternalServerError)
.WithModel(soeResponse.Error.Message);
}
var attributes = soeResponse.Result.Attributes;
// insert related tables
var featureClass = table;
var primaryKey = feature.FeatureId;
await connection.ExecuteAsync("delete from [wri].[dbo].county WHERE [featureId] = @id;" +
"delete from [wri].[dbo].FOCUSAREA WHERE [featureId] = @id;" +
"delete from [wri].[dbo].sgma WHERE [featureId] = @id;" +
"delete from [wri].[dbo].LANDOWNER WHERE [featureId] = @id",
new
{
id = primaryKey
});
//.........这里部分代码省略.........
示例2: FeatureModule
public FeatureModule(IQuery queries, IAttributeValidator validator, ISoeService soeService)
: base("/project/{id:int}")
{
Get["/feature/{featureId:int}", true] = async (_, ctx) =>
{
var model = this.Bind<SpecificFeatureRequest>();
// make sure feature type is valid
if (model.FeatureCategory == null || !FeatureCategoryToTable.Contains(model.FeatureCategory.ToLower()))
{
return Negotiate.WithReasonPhrase("Incomplete request")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("Category not found.");
}
IEnumerable<RelatedDetails> records;
var db = await queries.OpenConnection();
using (var connection = db.Connection)
{
if (!db.Open)
{
return Negotiate.WithReasonPhrase("Database Error")
.WithStatusCode(HttpStatusCode.InternalServerError)
.WithModel("Unable to connect to the database.");
}
// get the database table to use
var table = FeatureCategoryToTable.GetTableFrom(model.FeatureCategory);
records = await queries.RelatedDataQueryAsync(connection, new
{
table,
model.FeatureId
});
}
var response = new SpatialFeatureResponse
{
County = records.Where(x => x.Origin == "county"),
FocusArea = records.Where(x => x.Origin == "focus"),
SageGrouse = records.Where(x => x.Origin == "sgma"),
LandOwnership = records.Where(x => x.Origin == "owner"),
Nhd = records.Where(x => x.Origin == "nhd")
};
return response;
};
Post["/feature/create", true] = async (_, ctx) =>
{
var id = int.Parse(_.id);
var model = this.Bind<SaveFeatureRequest>();
// make sure we have all the user information.
if (string.IsNullOrEmpty(model.Token) || string.IsNullOrEmpty(model.Key))
{
return Negotiate.WithReasonPhrase("User not found")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("User not found.");
}
// make sure we have most of the attributes.
if (new[] {model.Category, model.Geometry}.Any(string.IsNullOrEmpty))
{
return Negotiate.WithReasonPhrase("Incomplete request")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("Missing required parameters. Category, geometry, or actions.");
}
// make sure feature type is valid
if (!FeatureCategoryToTable.Contains(model.Category))
{
return Negotiate.WithReasonPhrase("Incomplete request")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("Category not found.");
}
// get the database table to use
var table = FeatureCategoryToTable.GetTableFrom(model.Category);
var ten = TimeSpan.FromSeconds(600);
var db = await queries.OpenConnection();
using (
var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, ten,
TransactionScopeAsyncFlowOption.Enabled))
using (var connection = db.Connection)
{
if (!db.Open)
{
return Negotiate.WithReasonPhrase("Database Error")
.WithStatusCode(HttpStatusCode.InternalServerError)
.WithModel("Unable to connect to the database.");
}
var projects = await queries.ProjectMinimalQueryAsync(connection, new {id});
var project = projects.FirstOrDefault();
// make sure project id is valid
//.........这里部分代码省略.........