/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="userAccount"></param> public bool AddSimpleUser(User user, UserAccount userAccount) { var existingUser = RetrieveSimpleUser(user.Email); if (existingUser != null) { throw new Exception("This user with the assosiated Email Address already exists."); } if (!StringExtensions.IsValidEmail(user.Email)) { throw new Exception("Email Address entered isn't valid."); } var addUser = new User { UserId = user.UserId, FirstName = user.FirstName, LastName = user.LastName, DateOfBirth = user.DateOfBirth, Address = user.Address, Email = user.Email, Company = user.Company, PhoneNumber = user.PhoneNumber, }; var addUserAccount = new UserAccount() { IsAdmin = userAccount.IsAdmin, ConfirmedEmail = userAccount.ConfirmedEmail, IsAuthorized = userAccount.IsAuthorized, LastLogin = userAccount.LastLogin, SignupDate = userAccount.SignupDate, Locked = userAccount.Locked, LoginAttempts = userAccount.LoginAttempts, Username = userAccount.Username, Password = PasswordHash.CreateHash(userAccount.Password), UserAccountId = userAccount.UserAccountId, UserUserId = user.UserId, }; try { _context.Users.Add(addUser); _context.UserAccounts.Add(addUserAccount); _context.SaveChanges(); return true; } catch (Exception) { return false; } }
/// <summary> /// /// </summary> /// <param name="updatedUser"></param> public bool EditSimpleUserDetails(User updatedUser) { var existingUser = RetrieveSimpleUser(updatedUser.Email); if (existingUser == null) { throw new Exception("This user does not exist so cannot edit."); } existingUser.FirstName = updatedUser.FirstName; existingUser.LastName = updatedUser.LastName; existingUser.DateOfBirth = updatedUser.DateOfBirth; existingUser.Address = updatedUser.Address; existingUser.Email = updatedUser.Email; existingUser.Company = updatedUser.Company; existingUser.PhoneNumber = updatedUser.PhoneNumber; try { _context.SaveChanges(); return true; } catch (Exception) { return false; } }
public UserSecurityToken(User user) { UserId = user.UserId; }