本文整理汇总了C#中UserRepository.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.Commit方法的具体用法?C# UserRepository.Commit怎么用?C# UserRepository.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMySql
public static void GetMySql()
{
UserRepository rep = new UserRepository(new MySqlDbContext());
rep.Insert(new User { ID = new Guid("12736219-9398-4DBD-A392-BF8C5CCC3635"), Mobile = "01819421877", Password = "NewPassword", Username = "SiamDeath" });
rep.Commit();
var data = rep.Get(new Guid("C1C8D804-0645-4006-B9C8-192EBD944944"));
var collection = rep.GetAll().ToList();
}
示例2: GetSql
public static void GetSql()
{
UserRepository rep = new UserRepository(new WebApiDBContext());
rep.Insert(new User { ID = new Guid("19D40AEC-37B7-4114-A5BF-E4E3B3CFC97A"), Mobile = "01819421877", Password = "NewPassword", Username = "SiamDeath" });
rep.Commit();
var data = rep.Get(new Guid("C1C8D804-0645-4006-B9C8-192EBD944944"));
var collection = rep.GetAll().ToList();
}
示例3: ChangeIDCard
public void ChangeIDCard(string userName, string idCardNo, string chineseName)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(userName);
if (user != null)
{
user.ChangeIDCard(idCardNo, chineseName);
userRepository.Commit();
}
}
}
示例4: 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;
}
示例5: AddReference
public ActionResult AddReference(int counterId, int userId)
{
using (var db = new GazDbContext())
{
var userrepo = new UserRepository(db);
var counterrepo = new CountersRepository(db);
var user = userrepo.GetByID(userId);
var counter = counterrepo.GetByID(counterId);
user.User_Counters.Add(counter);
userrepo.Commit();
return Content("Ref added");
}
}
示例6: ChangeAchievement
public void ChangeAchievement(Achievement achievement)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(achievement.UserId);
if (user != null)
{
var _achievement = user.Achievements.SingleOrDefault<Achievement>(a => a.Year == DateTime.Now.Year && a.UserId == user.Id);
if (_achievement != null)
{
var id = _achievement.Id;
_achievement = Mapper.Map<Achievement>(achievement);
_achievement.Id = id;
}
else
user.Achievements.Add(achievement);
userRepository.Commit();
}
}
}
示例7: ChangePassword
public void ChangePassword(string userName, string oldPassword, string newPassword)
{
if (string.IsNullOrWhiteSpace(oldPassword))
throw new ArgumentNullException("oldPassword");
if (string.IsNullOrWhiteSpace(newPassword))
throw new ArgumentNullException("newPassword");
using (UserRepository userRepository = new UserRepository())
{
var account = userRepository.Get(userName);
if (account != null && DataCryptography.DecryptString(account.Password) == oldPassword)
{
account.ChangePassword(newPassword);
userRepository.Commit();
// send change password tips email
SendMail(account, HostSendMail.EmailCategory.ChangePassword);
}
else
{
// throw custermized exception
throw new UserNotExistException(Resource.UserMessages.ex_AccountIsNotExist);
}
}
}
示例8: ChangeUser
public void ChangeUser(string userName, string qq, bool gender)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(userName);
if (user != null)
{
user.QQ = qq;
user.Gender = gender;
userRepository.Commit();
}
}
}
示例9: ValidateIDCard
public bool ValidateIDCard(string userName, string idCardNo, string chineseName)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(userName);
if (user != null && user.IDCardNo == idCardNo && user.ChineseName == chineseName)
{
// TODO: call 3rd party id card validation
if (true)
{
user.IDCards.Add(new IDCard { ChineseName = chineseName, IDCardNo = idCardNo, UserId = user.Id });
user.IsIDCardValid = true;
userRepository.Commit();
return true;
}
}
return false;
}
}
示例10: UnlockAccount
public void UnlockAccount(string userName)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(userName);
if (user != null)
{
user.UnlockAccount();
userRepository.Commit();
}
}
}
示例11: ResetPassword
public void ResetPassword(string userName, string email)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(userName);
if (user != null && email == user.Email)
{
user.ResetPassword();
userRepository.Commit();
// send reset password email
SendMail(user, HostSendMail.EmailCategory.ResetPassword);
}
else
{
// throw custermized exception
throw new UserNotExistException(Resource.UserMessages.ex_AccountIsNotExist);
}
}
}
示例12: Register
public void Register(User user)
{
if (user == null)
throw new ArgumentNullException("user");
using (UserRepository userRepository = new UserRepository())
{
if (userRepository.CheckAccountExistByName(user.UserName))
{
// throw account name exists exception
throw new AccountIsExistException(string.Format(Resource.UserMessages.ex_AccountExist, user.UserName));
}
var accounts = userRepository.GetFiltered(a => a.Email == user.Email);
if (accounts.Count<User>() > 0)
{
// throw email exists exception
throw new AccountEmailExistException(string.Format(Resource.UserMessages.ex_EmailExist, user.Email));
}
userRepository.Add(user);
userRepository.Commit();
}
}
示例13: Recharge
public void Recharge(string userName, int coins)
{
using (UserRepository userRepository = new UserRepository())
{
var user = userRepository.Get(userName);
if (user != null)
{
// TODO: call 3rd party recharge request
userRepository.TrackEntity(user);
user.Recharge(coins);
var rechargeRecord = new RechargeRecord { Coins = coins, RechargeTime = DateTime.Now, UserId = user.Id };
user.RechargeRecords.Add(rechargeRecord);
userRepository.Commit();
// send recharege email
SendMail(user, HostSendMail.EmailCategory.Recharge);
}
}
}
示例14: WhenUserAdded_ThenUpdatesRepository
public void WhenUserAdded_ThenUpdatesRepository()
{
DatabaseTestUtility.DropCreateFirebrickDatabase();
var repository = new UserRepository(new DatabaseFactory());
var newUser = new User
{
DisplayName = "name",
Country = "United States",
PostalCode = "a1b2c3",
Password = "password",
UserName = "username"
};
repository.Add(newUser);
repository.Commit();
List<User> actualList = repository.GetAll().ToList();
Assert.Equal(1, actualList.Count);
Assert.Equal(newUser.DisplayName, actualList[0].DisplayName);
}
示例15: RegisterTest
public void RegisterTest()
{
IUserService accountSrv = new UserService();
UserAppService target = new UserAppService(accountSrv);
using (UserRepository accountRepository = new UserRepository())
{
var accounts = accountRepository.GetFiltered(a => a.AccountName == "zhangsan");
if (accounts != null && accounts.ToList<User>().Count > 0)
{
var existedAccount = accounts.Single<User>
(a => a.AccountName == "zhangsan");
if (existedAccount != null)
{
accountRepository.Remove(existedAccount);
accountRepository.Commit();
}
}
var accountAdd = User.CreateAccount(new Guid("D1111C18-A0BD-480B-99CA-AAF50B2D1818"), "zhangsan", "123456", "[email protected]",
120, false, "310123199009091244", "张三", "", true, false);
target.Register(accountAdd);
var accountInRepository = accountRepository.Get(accountAdd.Id);
Assert.AreEqual(accountInRepository.AccountName, accountAdd.AccountName);
}
}