本文整理汇总了C#中UserRepository.findById方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.findById方法的具体用法?C# UserRepository.findById怎么用?C# UserRepository.findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.findById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: delete
public Boolean delete()
{
//delete from user table
String deleteUserID = Request.Params["id"];
int id = int.Parse(deleteUserID);
IRepository<User> repository = new UserRepository();
User deletedUser = repository.findById(id);
if (deletedUser == null)
{
return false;
}
repository.Delete(deletedUser);
//delete from asp.netUser table
var context = new NetCafeWeb.Models.ApplicationDbContext();
var UserManager = new UserManager<NetCafeWeb.Models.ApplicationUser>(new UserStore<NetCafeWeb.Models.ApplicationUser>(context));
ApplicationUser aspSelectedUser = context.Users.Where(u => u.UserName.Equals((deletedUser.UserName), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
UserManager.DeleteAsync(aspSelectedUser);
return true;
}
示例2: updateUser
public bool updateUser(User selectedUser)
{
//Danger: selected user with new role inside
if(selectedUser != null)
{
IRepository<User> repository = new UserRepository();
//update in aspUser
User orginUser = repository.findById(selectedUser.UserID);
//find old role
Role oldRole = role_repo.findById(orginUser.RoleID);
string oldRoleName = oldRole.RoleName;
Role newRole = role_repo.findById(selectedUser.RoleID);
string newRoleName = newRole.RoleName;
var context = new NetCafeWeb.Models.ApplicationDbContext();
var UserManager = new UserManager<NetCafeWeb.Models.ApplicationUser>(new UserStore<NetCafeWeb.Models.ApplicationUser>(context));
ApplicationUser aspSelectedUser = context.Users.Where(u => u.UserName.Equals((selectedUser.UserName), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
var r1 = UserManager.RemoveFromRole(aspSelectedUser.Id, oldRoleName);
var r2 = UserManager.AddToRole(aspSelectedUser.Id, newRoleName);
if (r1.Succeeded && r2.Succeeded)
{
//update in user table
repository.Update(selectedUser);
return true;
}
else return false;
}
return false;
}
示例3: findAnUser
public User findAnUser(int id)
{
IRepository<User> repository = new UserRepository();
User user = repository.findById(id);
return user;
}