private User MockUser(int id) { Role r = _roles["Customer"]; var u = new User {UserId = id}; u.UserAccounts = new Collection<UserAccount> { new UserAccount {AccountNumber = id + "A", User = u, UserId = id, UserAccountId = id*100} }; u.UserRoles = new Collection<UserRole> { new UserRole {Role = r, RoleId = r.RoleId, UserId = id, UserRoleId = id*10} }; return u; }
private static string GetAccountNumber(User user) { UserAccount account = user.UserAccounts.FirstOrDefault(); return (account != null) ? account.AccountNumber : null; }
public void Add(User u) { _context.Users.Add(u); _context.SaveChanges(); }
private void RemoveUserAccount(User u) { UserAccount a = _userRepository.GetUserAccount(u.UserId); if (a != null) u.UserAccounts.Remove(a); }
public void Delete(User u) { _context.Users.Remove(u); _context.SaveChanges(); }
private void AddOrUpdateUserAccount(User u, string accountNumber) { UserAccount a = _userRepository.GetUserAccount(u.UserId); string accountno = (accountNumber.Length > Constants.MaxAccountNumberLength) ? accountNumber.Substring(0, Constants.MaxAccountNumberLength) : accountNumber; if (a == null) { a = new UserAccount {UserId = u.UserId, AccountNumber = accountno}; u.UserAccounts.Add(a); } else { u.UserAccounts.Remove(a); a = new UserAccount {UserId = u.UserId, AccountNumber = accountno}; u.UserAccounts.Add(a); } }
private void RemoveUserRole(User u, int roleId) { UserRole r = _userRepository.GetUserRole(u.UserId, roleId); if (r != null) u.UserRoles.Remove(r); }
private static void AddUserRole(User u, int roleId) { bool isbreeder = u.UserRoles.Count(x => x.RoleId == roleId) > 0; if (isbreeder) return; var r = new UserRole {UserId = u.UserId, RoleId = roleId}; u.UserRoles.Add(r); }
public int CreateUser(string username, string email, string password, string ip, string browser) { string uname = (username.Length > 20) ? username.Substring(0, Constants.MaxAccountNumberLength) : username; var u = new User { Username = uname, EmailAddress = email, Password = GeneratePasswordHash(password.Trim()), IPAddress = ip, BrowserInfo = browser, DateRegistered = DateTime.Now }; _userRepository.Add(u); u = GetUserByUsername(uname); if (u != null) return u.UserId; return -1; }
private static ProfileEditViewModel LoadProfileEditViewModel(User u) { var vm = new ProfileEditViewModel { OldUsername = u.Username, OldEmailAddress = u.EmailAddress }; return vm; }