예제 #1
0
        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();
        }
예제 #2
0
 /// <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;
 }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Clients EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToClients(Clients clients)
 {
     base.AddObject("Clients", clients);
 }
예제 #4
0
        private void AddUser(Clients user)
        {
            if (UserExists(user))
                throw new ArgumentException(TooManyUser);

            entities.Clients.AddObject(user);
        }
예제 #5
0
        public bool UserExists(Clients user)
        {
            if (user == null)
                return false;

            return (entities.Clients.SingleOrDefault(u => u.ClientId == user.ClientId || u.Email == user.Email) != null);
        }
예제 #6
0
        public Roles GetRoleForUser(Clients user)
        {
            if (!UserExists(user))
                throw new ArgumentException(MissingUser);

            return user.Roles;
        }
예제 #7
0
        public void DeleteUser(Clients user)
        {
            if (!UserExists(user))
                throw new ArgumentException(MissingUser);

            entities.Clients.DeleteObject(user);
        }