public int IncrementFailedLoginAttemptCount(AccountId accountId) { using (var db = new THCard()) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead })) { FailedLoginAttempt dbFailedLoginAttempt = FindFailedLoginAttempt(db, accountId.ToGuid()); if (dbFailedLoginAttempt == null) { db.FailedLoginAttempts.Add(new FailedLoginAttempt { AccountId = accountId.ToGuid(), FailedLoginAttemptCount = 0 }); db.SaveChanges(); transaction.Complete(); return(1); } else { ++dbFailedLoginAttempt.FailedLoginAttemptCount; db.SaveChanges(); transaction.Complete(); return(dbFailedLoginAttempt.FailedLoginAttemptCount); } } } }
public SaltedHash GetAccountPassword(AccountId accountId) { using (var db = new THCard()) { Account dbAccount = db.Accounts.Find(accountId); AssertFound(dbAccount); return(MapToHashedPassword(dbAccount)); } }
public SaltedHash GetAccountPassword(AccountId accountId) { using (var db = new THCard()) { Account dbAccount = db.Accounts.Find(accountId); AssertFound(dbAccount); return MapToHashedPassword(dbAccount); } }
public AccountManagement.User GetUser(UserId userId) { using (var db = new THCard()) { Guid userIdAsGuid = userId.ToGuid(); User dbUser = db.Users.SingleOrDefault(u => u.UserId == userIdAsGuid); AccountManagement.User user = MapToUser(dbUser); return user; } }
public AccountManagement.User GetUser(UserId userId) { using (var db = new THCard()) { Guid userIdAsGuid = userId.ToGuid(); User dbUser = db.Users.SingleOrDefault(u => u.UserId == userIdAsGuid); AccountManagement.User user = MapToUser(dbUser); return(user); } }
public AccountManagement.Account FindAccount(Username username) { using (var db = new THCard()) { Account dbAccount = FindAccountByUsername(username, db); if (dbAccount == null) { return null; } return MapAccount(dbAccount); } }
public AccountManagement.User GetUser(AccountId accountId) { Contract.Requires(accountId != null && !accountId.IsNew); using (var db = new THCard()) { Account dbAccount = db.Accounts.Find(accountId.ToGuid()); if (dbAccount == null) { throw new InvalidOperationException("Account not found."); } return MapToUser(dbAccount.User); } }
public AccountManagement.Account FindAccount(Username username) { using (var db = new THCard()) { Account dbAccount = FindAccountByUsername(username, db); if (dbAccount == null) { return(null); } return(MapAccount(dbAccount)); } }
public AccountManagement.Account GetAccount(AccountId accountId) { using (var db = new THCard()) { Account dbAccount = FindAccountById(db, accountId.ToGuid()); if (dbAccount != null) { return MapAccount(dbAccount); } else { return null; } } }
public AccountManagement.User GetUser(AccountId accountId) { Contract.Requires(accountId != null && !accountId.IsNew); using (var db = new THCard()) { Account dbAccount = db.Accounts.Find(accountId.ToGuid()); if (dbAccount == null) { throw new InvalidOperationException("Account not found."); } return(MapToUser(dbAccount.User)); } }
public AccountManagement.Account GetAccount(AccountId accountId) { using (var db = new THCard()) { Account dbAccount = FindAccountById(db, accountId.ToGuid()); if (dbAccount != null) { return(MapAccount(dbAccount)); } else { return(null); } } }
public void SaveUser(AccountManagement.User user) { Contract.Requires(user != null && !user.Id.IsNew); using (var db = new THCard()) { using (var transaction = new TransactionScope()) { User dbUser = db.Users.Find(user.Id.ToGuid()); dbUser.FirstName = user.FullName.FirstName.ToString(); dbUser.MiddleName = user.FullName.MiddleName.ToString(); dbUser.LastName = user.FullName.FamilyName.ToString(); db.SaveChanges(); transaction.Complete(); } } }
public void CreateUser(AccountManagement.User user) { Contract.Requires(user != null && user.Id.IsNew); using (var db = new THCard()) { using (var transaction = new TransactionScope()) { var dbUser = new User(); dbUser.FirstName = user.FullName.FirstName.ToString(); dbUser.MiddleName = user.FullName.MiddleName.ToString(); dbUser.LastName = user.FullName.FamilyName.ToString(); db.Users.Add(dbUser); db.SaveChanges(); transaction.Complete(); user.Id = new UserId(dbUser.UserId); } } }
public void CreateAccount(AccountManagement.Account account, SaltedHash passwordHash, UserId userId) { Contract.Assert(account.AccountId.IsNew); using (var db = new THCard()) { using (var transaction = new TransactionScope()) { var dbAccount = new Account { Username = account.Username.ToString(), UserId = userId.ToGuid(), AccountPassword = new AccountPassword { PasswordHash = passwordHash.Hash, Salt = passwordHash.Salt } }; db.Accounts.Add(dbAccount); db.SaveChanges(); transaction.Complete(); account.AccountId = new AccountId(dbAccount.AccountId); } } }
public int IncrementFailedLoginAttemptCount(AccountId accountId) { using (var db = new THCard()) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead })) { FailedLoginAttempt dbFailedLoginAttempt = FindFailedLoginAttempt(db, accountId.ToGuid()); if (dbFailedLoginAttempt == null) { db.FailedLoginAttempts.Add(new FailedLoginAttempt {AccountId = accountId.ToGuid(), FailedLoginAttemptCount = 0}); db.SaveChanges(); transaction.Complete(); return 1; } else { ++dbFailedLoginAttempt.FailedLoginAttemptCount; db.SaveChanges(); transaction.Complete(); return dbFailedLoginAttempt.FailedLoginAttemptCount; } } } }
private static FailedLoginAttempt FindFailedLoginAttempt(THCard db, Guid accountId) { return(db.FailedLoginAttempts.SingleOrDefault(fla => fla.AccountId == accountId)); }
private static FailedLoginAttempt FindFailedLoginAttempt(THCard db, Guid accountId) { return db.FailedLoginAttempts.SingleOrDefault(fla => fla.AccountId == accountId); }
private static Account FindAccountByUsername(Username username, THCard db) { string usernameAsString = username.ToString(); return db.Accounts.FirstOrDefault(a => a.Username == usernameAsString); }
private static Account FindAccountById(THCard db, Guid accountId) { Account dbAccount = db.Accounts.SingleOrDefault(a => a.AccountId == accountId); return(dbAccount); }
private static Account FindAccountById(THCard db, Guid accountId) { Account dbAccount = db.Accounts.SingleOrDefault(a => a.AccountId == accountId); return dbAccount; }
private static Account FindAccountByUsername(Username username, THCard db) { string usernameAsString = username.ToString(); return(db.Accounts.FirstOrDefault(a => a.Username == usernameAsString)); }