Пример #1
0
        public bool UpdateRole(DataUsers user)
        {
            bool noError = true;

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("dbo.sp_UserUpdateRole", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@UserID", user.UserID);
                        command.Parameters.AddWithValue("@RoleID", user.RoleID);

                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception);
            }
            return(noError);
        }
Пример #2
0
        public bool CreateUser(DataUsers user) //creating an instance of DataUsers called user
                                               //if sucessful no erros it will return true
        {
            bool noError = true;

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("dbo.sp_UserCreate", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.AddWithValue("@Email", user.Email);
                        command.Parameters.AddWithValue("@Hash", user.Hash);
                        command.Parameters.AddWithValue("@Salt", user.Salt);
                        command.Parameters.AddWithValue("@Address", user.Address);
                        command.Parameters.AddWithValue("@FirstName", user.FirstName);
                        command.Parameters.AddWithValue("@LastName", user.LastName);
                        command.Parameters.AddWithValue("@Birthday", DateTime.Now);
                        command.Parameters.AddWithValue("@Phone", user.Phone);
                        command.Parameters.AddWithValue("@AccountCreateDate", DateTime.Now);
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception);
            }
            return(noError);
        }
Пример #3
0
        public bool UpdateUser(DataUsers user)
        {
            bool noError = true;

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("dbo.sp_UserUpdateByID", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@UserID", user.UserID);
                        command.Parameters.AddWithValue("@Email", user.Email);
                        command.Parameters.AddWithValue("@Address", user.Address);
                        command.Parameters.AddWithValue("@FirstName", user.FirstName);
                        command.Parameters.AddWithValue("@LastName", user.LastName);
                        command.Parameters.AddWithValue("@Birthday", user.Birthday);
                        command.Parameters.AddWithValue("@Phone", user.Phone);
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception);
            }

            return(noError);
        }
Пример #4
0
        //Get Hash and Salt from User by Email for Password Validation
        public DataUsers GetCredentials(string Email) //TAKES in UserEmail,returns DataUser
        {
            DataUsers userByEmail = new DataUsers();  //new instance of DataUsers

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open(); //opens connection string to database
                    using (SqlCommand command = new SqlCommand("dbo.sp_UsersGetCredentialsByEmail", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@Email", Email); //passing email as parameter for stored procedure

                        SqlDataReader reader = command.ExecuteReader();   //creating instance of SQLDataReader
                        while (reader.Read())                             //executes until SQLDataReader is finished reading
                        {
                            userByEmail.UserID = reader.GetInt32(0);
                            userByEmail.RoleID = reader.GetInt32(1);
                            userByEmail.Email  = reader.GetString(2);
                            userByEmail.Hash   = reader.GetString(3);
                            userByEmail.Salt   = reader.GetString(4);
                        }
                        command.ExecuteNonQuery();//executes stored procedure
                    }
                }//<---closes and disposes of connection
            }
            catch (Exception exception)//catches the error
            {
                //gun being fired off
                Logger.LogError(exception); //passes the info Logger.LogError
            }
            return(userByEmail);            // returns DataUser with Hash and Salt
        }
Пример #5
0
        public void AddUserToSnapshot(User newUser)
        {
            cUser newDataUser = new cUser
            {
                Id             = 0, //not necessary - generated in data layer
                Login          = newUser.Login,
                FirstName      = newUser.FirstName,
                LastName       = newUser.LastName,
                PasswordPublic = SecurityUtils.EncryptPlainTextToCipherText(newUser.PasswordPrivate)
            };

            DataUsers.AddUser(newDataUser);
        }
Пример #6
0
        public DataUsers Map(ModelUser mUser)
        {
            DataUsers dUser = new DataUsers();

            dUser.UserID            = mUser.UserID;
            dUser.RoleID            = mUser.RoleID;
            dUser.Email             = mUser.Email;
            dUser.Hash              = mUser.Hash;
            dUser.Salt              = mUser.Salt;
            dUser.Address           = mUser.Address;
            dUser.FirstName         = mUser.FirstName;
            dUser.LastName          = mUser.LastName;
            dUser.Birthday          = mUser.Birthday;
            dUser.Phone             = mUser.Phone;
            dUser.AccountCreateDate = mUser.AccountCreateDate;

            return(dUser);
        }
Пример #7
0
        public ModelUser Map(DataUsers dUser)
        {
            ModelUser mUser = new ModelUser();

            mUser.UserID            = dUser.UserID;
            mUser.RoleID            = dUser.RoleID;
            mUser.Email             = dUser.Email;
            mUser.Hash              = dUser.Hash;
            mUser.Salt              = dUser.Salt;
            mUser.Address           = dUser.Address;
            mUser.FirstName         = dUser.FirstName;
            mUser.LastName          = dUser.LastName;
            mUser.Birthday          = dUser.Birthday;
            mUser.Phone             = dUser.Phone;
            mUser.AccountCreateDate = dUser.AccountCreateDate;
            mUser.PhotoURL          = dUser.Hash;

            return(mUser);
        }
Пример #8
0
        public User GetUserByName(String FirstName, String LastName)
        {
            cUser user = DataUsers.GetUserByName(FirstName, LastName);

            if (user != null)
            {
                return(new User
                {
                    Id = user.Id,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Login = user.Login,
                    PasswordPrivate = SecurityUtils.DecryptCipherTextToPlainText(user.PasswordPublic)
                });
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
        public List <DataUsers> GetAllUsers()
        {
            List <DataUsers> allUsers = new List <DataUsers>();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand("dbo.sp_UsersGetAll", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            DataUsers dUser = new DataUsers();

                            dUser.UserID            = reader.GetInt32(0);
                            dUser.RoleID            = reader.GetInt32(1);
                            dUser.Email             = reader.GetString(2);
                            dUser.Address           = reader.GetString(3);
                            dUser.FirstName         = reader.GetString(4);
                            dUser.LastName          = reader.GetString(5);
                            dUser.Birthday          = reader.GetDateTime(6);
                            dUser.Phone             = reader.GetString(7);
                            dUser.AccountCreateDate = reader.GetDateTime(8);

                            allUsers.Add(dUser);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception);
            }
            return(allUsers);
        }
Пример #10
0
        public List <User> GetUsers()
        {
            DataUsers = DataUsers.GetUsersFromSnapshot();
            List <User> result = new List <User>();

            if (DataUsers is null)
            {
                return(null);
            }
            foreach (cUser usr in DataUsers.Users)
            {
                result.Add(new User
                {
                    Login           = usr.Login,
                    PasswordPrivate = SecurityUtils.DecryptCipherTextToPlainText(usr.PasswordPublic),
                    FirstName       = usr.FirstName,
                    LastName        = usr.LastName,
                    Id = Convert.ToInt32(usr.Id),
                });
            }
            AppUsers = result;
            return(result);
        }
Пример #11
0
 public void SaveSnapshotToFile(String filename)
 {
     DataUsers.SaveUserSnapshot(filename);
 }
Пример #12
0
 internal void LoadFromSnapshot()
 {
     DataUsers.GetUsersFromSnapshot();
 }
Пример #13
0
 public void LoadXmlStreamSnapshot(String filename = "Users.xml")
 {
     DataUsers.GetUserStreamFromXML(filename);
 }