本文整理汇总了C#中IQuery.UserQueryAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IQuery.UserQueryAsync方法的具体用法?C# IQuery.UserQueryAsync怎么用?C# IQuery.UserQueryAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQuery
的用法示例。
在下文中一共展示了IQuery.UserQueryAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProjectModule
public ProjectModule(IQuery queries)
: base("/project")
{
Get["/{id:int}", true] = async (_, ctx) =>
{
var id = int.Parse(_.id);
var model = this.Bind<UserDetailsRequest>();
var response = new ProjectWithFeaturesResponse();
var incompleteAttributes = string.IsNullOrEmpty(model.Token) || string.IsNullOrEmpty(model.Key);
response.AllowEdits = !incompleteAttributes;
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.");
}
var project = await queries.ProjectQueryAsync(connection, new {id});
response.Project = project;
var features = await queries.FeatureQueryAsync(connection, new {id});
response.Features = features;
var reason = "";
if (incompleteAttributes)
{
return Negotiate.WithModel(response)
.WithStatusCode(HttpStatusCode.OK)
.WithHeader("reason", "incomplete attributes");
}
var users = await queries.UserQueryAsync(connection, new {key = model.Key, token = model.Token});
var user = users.FirstOrDefault();
// make sure user is valid
if (user == null)
{
response.AllowEdits = false;
reason = "User is null. ";
}
else if (response.Project == null)
{
response.AllowEdits = false;
reason = "Project not found. ";
}
// anonymous and public users cannot create features
else if (new[] {"GROUP_ANONYMOUS", "GROUP_PUBLIC"}.Contains(user.Role))
{
response.AllowEdits = false;
reason += "Roles is anonymous or public. ";
}
// if project has features no or null, block feature creation
else if (response.Project.Features == "No" && user.Role != "GROUP_ADMIN")
{
response.AllowEdits = false;
reason += "Project is designated to have no features. ";
}
// cancelled and completed projects cannot be edited
else if (new[] {"Cancelled", "Completed"}.Contains(response.Project.Status) &&
user.Role != "GROUP_ADMIN")
{
response.AllowEdits = false;
}
// check if a user is a contributor
else if (response.Project.ProjectManagerId != user.Id && user.Role != "GROUP_ADMIN")
{
var counts = await queries.ContributorQueryAsync(connection, new {id, userId = user.Id});
var count = counts.FirstOrDefault();
if (count == 0)
{
response.AllowEdits = false;
reason += "User is not a contributor. ";
}
}
return Negotiate.WithModel(response)
.WithHeader("reason", reason);
}
};
}
示例2: FeatureModule
//.........这里部分代码省略.........
.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
if (project == null)
{
return Negotiate.WithReasonPhrase("Project not found")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("Project not found.");
}
var users = await queries.UserQueryAsync(connection, new {key = model.Key, token = model.Token});
var user = users.FirstOrDefault();
// make sure user is valid
if (user == null)
{
return Negotiate.WithReasonPhrase("User not found")
.WithStatusCode(HttpStatusCode.BadRequest)
.WithModel("User not found.");
}
// cancelled and completed projects cannot be edited
if (new[] {"Cancelled", "Completed"}.Contains(project.Status) && user.Role != "GROUP_ADMIN")
{
return Negotiate.WithReasonPhrase("Project Status")
.WithStatusCode(HttpStatusCode.PreconditionFailed)
.WithModel("A cancelled or completed project cannot be modified.");
}
// anonymous and public users cannot create features
if (new[] {"GROUP_ANONYMOUS", "GROUP_PUBLIC"}.Contains(user.Role))
{
return Negotiate.WithReasonPhrase("Role")
.WithStatusCode(HttpStatusCode.Unauthorized)
.WithModel("Project manager and contributors are only allowed to modify this project.");
}
// if project has features no or null, block feature creation
if (project.Features == "No" && user.Role != "GROUP_ADMIN")
{
return Negotiate.WithReasonPhrase("Project settings")
.WithStatusCode(HttpStatusCode.PreconditionFailed)
.WithModel(