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;
 }
コード例 #2
0
 private static string GetAccountNumber(User user)
 {
     UserAccount account = user.UserAccounts.FirstOrDefault();
     return (account != null) ? account.AccountNumber : null;
 }
コード例 #3
0
 public void Add(User u)
 {
     _context.Users.Add(u);
     _context.SaveChanges();
 }
コード例 #4
0
 private void RemoveUserAccount(User u)
 {
     UserAccount a = _userRepository.GetUserAccount(u.UserId);
     if (a != null) u.UserAccounts.Remove(a);
 }
コード例 #5
0
 public void Delete(User u)
 {
     _context.Users.Remove(u);
     _context.SaveChanges();
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 private void RemoveUserRole(User u, int roleId)
 {
     UserRole r = _userRepository.GetUserRole(u.UserId, roleId);
     if (r != null) u.UserRoles.Remove(r);
 }
コード例 #8
0
 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);
 }
コード例 #9
0
 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;
 }
コード例 #10
0
 private static ProfileEditViewModel LoadProfileEditViewModel(User u)
 {
     var vm = new ProfileEditViewModel
     {
         OldUsername = u.Username,
         OldEmailAddress = u.EmailAddress
     };
     return vm;
 }