本文整理汇总了C#中IUserService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IUserService.Add方法的具体用法?C# IUserService.Add怎么用?C# IUserService.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserService
的用法示例。
在下文中一共展示了IUserService.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserServiceTests
public UserServiceTests()
{
this.service = new UserService();
service.Add(new User { Name = "John" }
);
service.Add(new User { Name = "Mike" }
);
}
示例2: UserServiceTests
public UserServiceTests()
{
this.service = new UserService();
service.Add(new User { Login = "Sabina" }
);
service.Add(new User { Login = "Dimas" }
);
}
示例3: UserModule
public UserModule(IUserService userService, IMappingEngine mappingEngine)
: base("data/users", mappingEngine, UserRole.Admin)
{
Get["/"] = args =>
{
var entities = userService.Search(
Context.RequestedPage(),
null,
Context.SortCriteria<User>(),
Context.SearchTerms<User>());
return MapToResultList<SystemUser, Encore.Web.Models.User>(entities);
};
Get["/{id}"] = args =>
{
var entity = userService.Get(new Guid(args.id));
if (entity == null)
{
return Negotiate.WithStatusCode(HttpStatusCode.NotFound);
}
return MapTo<Encore.Web.Models.User>(entity);
};
Put["/{id}"] = args =>
{
var model = this.BindAndValidate<Models.User>();
if (!ModelValidationResult.IsValid)
{
return RespondWithValidationFailure(ModelValidationResult);
}
var authorizedUser = Context.GetAuthorizedUser();
var updateEntity = MapTo<SystemUser>(model);
var updateId = new Guid(args.id);
var updatedUser = userService.UpdateUser(authorizedUser.Id, updateId, updateEntity);
if (authorizedUser.Id == updateId)
{
Context.SetupSession(updatedUser);
}
return MapTo<User>(updatedUser);
};
Post["/"] = args =>
{
var model = this.BindAndValidate<Models.User>();
if (!ModelValidationResult.IsValid)
{
return RespondWithValidationFailure(ModelValidationResult);
}
var addEntity = MapTo<SystemUser>(model);
var user = userService.Add(addEntity);
if (user == null)
{
return HttpStatusCode.Unauthorized;
}
return MapTo<User>(user);
};
Delete["/{id}"] = args =>
{
var authorizedUser = Context.GetAuthorizedUser();
var deleteId = new Guid(args.id);
return userService.DeleteUser(authorizedUser.Id, deleteId);
};
}