本文整理汇总了C#中IUserRepository.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.GetAsync方法的具体用法?C# IUserRepository.GetAsync怎么用?C# IUserRepository.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.GetAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserModule
public UserModule(IUserService userService, IUserRepository userRepository)
: base("/api/v1/users")
{
Before += ctx =>
{
return null;
};
Get["/", true] = async (_, token) =>
{
var users = await userService.GetUsers();
return users;
};
// ?fiter={condition}&limit={limit}&offset={offset}
Get["/", ctx => ctx.Request.Url.Query != string.Empty, true] = async (_, token) =>
{
string filterString = this.Request.Query.filter;
var filter = JsonConvert.DeserializeObject<dynamic>(filterString);
int limit = this.Request.Query.limit;
int offset = this.Request.Query.offset;
var users = await userRepository.GetAsync(u => true, limit, offset, u => u.Name, true);
return users;
};
Post["/", true] = async (_, token) =>
{
//using (var sr = new StreamReader(this.Request.Body))
//{
// var json = sr.ReadToEnd();
//}
var user = this.Bind<User>();
await userService.AddUser(user);
return HttpStatusCode.Created;
};
Put["/{id}", true] = async (_, token) =>
{
var user = this.Bind<User>();
bool success = await userRepository.UpdateAsync(user);
return success ? HttpStatusCode.OK : HttpStatusCode.BadRequest;
};
Delete["/{id}", true] = async (_, token) =>
{
string id = _.id;
bool success = await userRepository.DeleteAsync(_.id);
return success ? HttpStatusCode.OK : HttpStatusCode.BadRequest;
};
Options["/"] = route => new Response();
}