本文整理汇总了C#中UserRepository.Save方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.Save方法的具体用法?C# UserRepository.Save怎么用?C# UserRepository.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReturnsTrueIfEmailExistsForDifferentUser
public void ReturnsTrueIfEmailExistsForDifferentUser()
{
var repository = new UserRepository(null, SessionSource.CreateSession());
var user = new User { Name = "test", Credentials = new Credentials("[email protected]", "pass") };
repository.Save(new User {Name = "test", Credentials = new Credentials("[email protected]", "pass")});
Assert.True(repository.EmailExists(user));
}
示例2: ChangePassword
public ActionResult ChangePassword(StudentChangePasswordVM model)
{
if (!ModelState.IsValid)
{
return View();
}
if (model.NewPassword != model.NewPasswordRepeat)
{
ModelState.AddModelError("Error", "New password dont match");
return View(model);
}
UserRepository<Student> stuRepo = new UserRepository<Student>();
Student student = stuRepo.GetByID(model.StudentID);
Passphrase hash = PasswordHasher.Hash(model.OldPassword);
if (PasswordHasher.Equals(model.OldPassword, student.Salt, student.Hash))
{
Passphrase hash2 = PasswordHasher.Hash(model.NewPassword);
student.Salt = hash2.Salt;
student.Hash = hash2.Hash;
stuRepo.Save(student);
}
else
{
ModelState.AddModelError("Error", "Old password dont match");
return View(model);
}
return RedirectToAction("Index", "Student");
}
示例3: Index
public ViewResult Index(string Name, string Email, string Password)
{
try
{
UserRepository userRep = new UserRepository();
Expression<Func<t_user, bool>> filter =
x => (x.mail == Email && Email != null);
List<t_user> users = userRep.Get(filter).ToList();
LoginModel model = new LoginModel();
if (users.Count > 0)
{
return View(model);
}
else
{
t_user newUser = new t_user();
newUser.name = Name;
newUser.mail = Email;
newUser.password = Password;
newUser.roleID = 2;
userRep.Save(newUser);
model.Name = Name;
model.Email = Email;
model.Password = Password;
}
return View(model);
}
catch (Exception)
{
return null;
}
}
示例4: AddUser_should_save
public void AddUser_should_save()
{
string username = "save" + Guid.NewGuid();
var user = new User
{
Email = "[email protected]",
FirstName = "john",
IsActive = true,
LastName = "haigh",
PasswordHash = "asdf",
Username = username
};
var svc = new UserService();
svc.AddUser(user);
var repo = new UserRepository();
var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();
// Test
repoUser.ShouldNotBeNull();
// Cleanup user
repo.Delete(repoUser);
repo.Save();
var results2 = repo.Find(u => u.Username == username);
var userFound2 = results2.FirstOrDefault();
Assert.IsNull(userFound2, "Tried to get user but the user was found");
}
示例5: UserExample
public void UserExample()
{
var interests = new HashSet<string> { "distributed systems", "Erlang" };
var joe = new User("Joe", "Armstrong", interests);
var entityManager = new EntityManager(client);
entityManager.Add(joe);
var repo = new UserRepository(client);
repo.Save(joe);
joe.VisitPage();
joe.AddInterest("riak");
repo.UpgradeAccount(joe);
var joeFetched = repo.Get(joe.ID);
Assert.GreaterOrEqual(joe.PageVisits, 0);
Assert.Contains("riak", joeFetched.Interests.ToArray());
PrintObject(joeFetched);
repo.DowngradeAccount(joe);
joeFetched = repo.Get(joe.ID);
PrintObject(joeFetched);
}
示例6: ReturnsFalseIfEmailBelongsToUser
public void ReturnsFalseIfEmailBelongsToUser()
{
var repository = new UserRepository(null, SessionSource.CreateSession());
var user = new User { Name = "test", Credentials = new Credentials("[email protected]", "pass") };
repository.Save(user);
Assert.False(repository.EmailExists(user));
}
示例7: Find_By_Guid
public void Find_By_Guid()
{
IUserRepository userRepository = new UserRepository(this.Client, this.Database);
User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
userRepository.Save(accountUser);
User accountUserLoaded = userRepository.Find(accountUser.Guid);
Assert.IsTrue(accountUserLoaded.Id == accountUserLoaded.Id);
}
示例8: Find_By_Email_And_Password
public void Find_By_Email_And_Password()
{
IUserRepository userRepository = new UserRepository(this.Client, this.Database);
User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
userRepository.Save(accountUser);
User accountUserFound = userRepository.Find(accountUser.Email, accountUser.Password);
Assert.IsNotNull(accountUserFound);
}
示例9: GivenAUserRepository_WhenIAskForUsers_UsersAreReturned
public void GivenAUserRepository_WhenIAskForUsers_UsersAreReturned()
{
var ctx = new BaillieGiffordEntities();
var repo = new UserRepository(ctx);
repo.Create(new User { EMail = "foo.com", Name = "bar" });
repo.Create(new User { EMail = "foo.com", Name = "bar" });
repo.Save();
var users = repo.Entities.ToList();
users.Count.Should().Be(2);
}
示例10: ReturnsDeveloperIfCredentialsAreValid
public void ReturnsDeveloperIfCredentialsAreValid()
{
var encryptor = Dynamic<IEncryptor>();
var repository = new UserRepository(encryptor, SessionSource.CreateSession());
encryptor.Stub(e => e.IsMatch(null, null)).IgnoreArguments().Return(true);
ReplayAll();
repository.Save(new User { Name = "#18", Credentials = new Credentials { Email = "[email protected]", Password = "hashed" } });
var user = repository.FindByCredentials(new Credentials("[email protected]", "marron"));
Assert.Equal("#18", user.Name);
}
示例11: ReturnsNullIfPasswordsDontMatch
public void ReturnsNullIfPasswordsDontMatch()
{
var encryptor = Dynamic<IEncryptor>();
var repository = new UserRepository(encryptor, SessionSource.CreateSession());
encryptor.Expect(e => e.IsMatch("marron", "hashed")).Return(false);
ReplayAll();
repository.Save(new User { Name = "#18", Credentials = new Credentials { Email = "[email protected]", Password = "hashed" } });
Assert.Null(repository.FindByCredentials(new Credentials("[email protected]", "marron")));
encryptor.VerifyAllExpectations();
}
示例12: Find_By_ForgotPassword
public void Find_By_ForgotPassword()
{
IUserRepository userRepository = new UserRepository(this.Client, this.Database);
User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
userRepository.Save(accountUser);
accountUser.ForgotPasswordGuid = Guid.NewGuid();
userRepository.Update(accountUser);
User userFound = userRepository.FindByForgotPassword(accountUser.ForgotPasswordGuid);
Assert.IsNotNull(userFound);
}
示例13: should_save_new_registration_with_assigned_id
public void should_save_new_registration_with_assigned_id()
{
var User = new domain.Users.User
{
CreationDate = DateTime.Now,
Email = "[email protected]",
Password = "Hello",
UserName = "Jude"
};
var userRepository = new UserRepository(sessionFactory);
userRepository.Save(User);
User.Id.Should().NotBe(Guid.Empty);
}
示例14: RegisterUser
public UserModel RegisterUser(UserModel model, string password)
{
var userRepository = new UserRepository();
var salt = BCryptHelper.GenerateSalt();
var passwordHash = BCryptHelper.HashPassword(password, salt);
model.Salt = salt;
model.Password = passwordHash;
userRepository.Save(model);
userRepository.Commit();
return model;
}
示例15: Save
public void Save()
{
IUserRepository iUserRepository = new UserRepository(this.connectionString);
User user = new User
(
18,
AppActs.DomainModel.Enum.SexType.Male,
Guid.NewGuid(),
DateTime.Now
);
iUserRepository.Save(this.Application.Id, this.Device.Id, user);
}