public void CreateUser(string email, string firstname, string lastname, DateTime dateOfBirth, bool sex, int roleName, string password) { Roles role = GetRole(roleName); if (string.IsNullOrEmpty(email.Trim())) throw new ArgumentException("The email address provided is invalid. Please check the value and try again."); if (string.IsNullOrEmpty(firstname.Trim())) throw new ArgumentException("The name provided is invalid. Please check the value and try again."); if (string.IsNullOrEmpty(lastname.Trim())) throw new ArgumentException("The name provided is invalid. Please check the value and try again."); if (string.IsNullOrEmpty(password.Trim())) throw new ArgumentException("The password provided is invalid. Please enter a valid password value."); if (!RoleExists(role)) throw new ArgumentException("The role selected for this user does not exist! Contact an administrator!"); if (this.entities.Clients.Any(user => user.Email == email)) throw new ArgumentException("Email already exists. Please enter a different email."); var newUser = new Clients(); { newUser.Email = email; newUser.FirstName = firstname; newUser.LastName = lastname; newUser.DateOfBirth = dateOfBirth.Date; newUser.Sex = sex; newUser.AddressId = 2; //Hardcoded, addressId = 2 newUser.RoleId = role.RoleId; newUser.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Trim(), "md5"); }; try { AddUser(newUser); } catch (ArgumentException ae) { throw ae; } catch (Exception e) { throw new ArgumentException("The authentication provider returned an error. Please verify your entry and try again. " + "If the problem persists, please contact your system administrator."); } // Immediately persist the user data Save(); }
/// <summary> /// Create a new Clients object. /// </summary> /// <param name="clientId">Initial value of the ClientId property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="dateOfBirth">Initial value of the DateOfBirth property.</param> /// <param name="sex">Initial value of the Sex property.</param> /// <param name="addressId">Initial value of the AddressId property.</param> /// <param name="roleId">Initial value of the RoleId property.</param> /// <param name="password">Initial value of the Password property.</param> public static Clients CreateClients(global::System.Int32 clientId, global::System.String email, global::System.String firstName, global::System.String lastName, global::System.DateTime dateOfBirth, global::System.Boolean sex, global::System.Int32 addressId, global::System.Int16 roleId, global::System.String password) { Clients clients = new Clients(); clients.ClientId = clientId; clients.Email = email; clients.FirstName = firstName; clients.LastName = lastName; clients.DateOfBirth = dateOfBirth; clients.Sex = sex; clients.AddressId = addressId; clients.RoleId = roleId; clients.Password = password; return clients; }
/// <summary> /// Deprecated Method for adding a new object to the Clients EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToClients(Clients clients) { base.AddObject("Clients", clients); }
private void AddUser(Clients user) { if (UserExists(user)) throw new ArgumentException(TooManyUser); entities.Clients.AddObject(user); }
public bool UserExists(Clients user) { if (user == null) return false; return (entities.Clients.SingleOrDefault(u => u.ClientId == user.ClientId || u.Email == user.Email) != null); }
public Roles GetRoleForUser(Clients user) { if (!UserExists(user)) throw new ArgumentException(MissingUser); return user.Roles; }
public void DeleteUser(Clients user) { if (!UserExists(user)) throw new ArgumentException(MissingUser); entities.Clients.DeleteObject(user); }