本文整理汇总了C#中UserRepository.GetUserById方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetUserById方法的具体用法?C# UserRepository.GetUserById怎么用?C# UserRepository.GetUserById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.GetUserById方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldCreateNewUserAndReturnHisId
public void ShouldCreateNewUserAndReturnHisId()
{
var repo = new UserRepository();
int userId = repo.CreateUser("user_name", "password", "name", "address", "phone");
var user = repo.GetUserById(userId);
Assert.IsNotNull(user);
Assert.AreEqual("user_name",user.AccountName);
}
示例2: ShouldReturnUserById
public void ShouldReturnUserById()
{
const string accountName = "super_user";
var repo = new UserRepository();
repo.CreateUser("user_name1", "password", "name1", "address", "phone");
repo.CreateUser(accountName, "password", "name2", "address", "phone");
var bankUser = repo.GetUserById(1);
Assert.AreEqual(accountName,bankUser.AccountName);
}
示例3: ChangePassword
public ActionResult ChangePassword(LocalPasswordModel model)
{
try
{
if (model.NewPassword.Equals(model.OldPassword))
throw new Exception("Please use some other password, New Password should not be same as old password.");
var userRepository = new UserRepository();
var user = userRepository.GetUserById(int.Parse(Session["PatientId"].ToString()));
user.Password = model.NewPassword;
userRepository.UpdatePassword(user);
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
return View(model);
}
return RedirectToLocal();
}
示例4: GeneratePasswordResetToken
public static string GeneratePasswordResetToken(string userName)
{
if (string.IsNullOrEmpty(userName))
{
throw new ArgumentException("Username cannot be empty");
}
var repo = new UserRepository();
var userId = VerifyUserNameHasConfirmedAccount(userName, false);
var user = repo.GetUserById(userId);
if (user == null)
return null;
if (user.PasswordVerificationTokenExpirationDate.HasValue &&
user.PasswordVerificationTokenExpirationDate.Value > DateTime.UtcNow)
{
return user.PasswordVerificationToken;
}
var token = GenerateToken();
user.PasswordVerificationToken = token;
user.PasswordVerificationTokenExpirationDate =
DateTime.UtcNow.AddMinutes(TokenExpirationInMinutesFromNow);
repo.Update(user);
return token;
}
示例5: GetUser
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
if (providerUserKey == null)
{
throw new ArgumentNullException("providerUserKey");
}
if (!(providerUserKey is Guid))
{
throw new ArgumentException(SR.GetString(SR.Membership_InvalidProviderUserKey), "providerUserKey");
}
var dbo = new UserRepository(this.Name, _sqlConnectionString, _commandTimeout);
var user = dbo.GetUserById(providerUserKey);
if (user == null)
return null;
return new MembershipUser(this.Name,
user.UserName,
user.UserId,
user.Email,
user.PasswordQuestion,
null,
user.IsApproved,
user.IsLockedOut,
user.LastActivityDate,
user.LastLoginDate.GetValueOrDefault(),
user.LastLoginDate.GetValueOrDefault(),
user.LastPasswordChangedDate.GetValueOrDefault(),
user.LastLockoutDate.GetValueOrDefault());
}