Esempio n. 1
0
        public void UpdateUser(User user)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = connectionString;
            conn.Open();

            string query = @"sp_UpdateUser";

            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = query;
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@UserID",
                SqlDbType     = System.Data.SqlDbType.Int,
                Value         = user.UserID
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@UserName",
                SqlDbType     = System.Data.SqlDbType.VarChar,
                Value         = user.UserName,
                Size          = user.UserName.Length
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@UserPassword",
                SqlDbType     = System.Data.SqlDbType.VarChar,
                Value         = SHA1Encoder.Encode(user.UserPassword),
                Size          = user.UserPassword.Length
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@IsActive",
                SqlDbType     = System.Data.SqlDbType.Bit,
                Value         = user.IsActive
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@RoleID",
                SqlDbType     = System.Data.SqlDbType.Int,
                Value         = user.RoleID
            });

            cmd.ExecuteNonQuery();

            cmd.Dispose();
            conn.Close();
        }
Esempio n. 2
0
        public void Encode_Returns_Proper_Value_When_Empty()
        {
            //Arrange
            string expectedValue = "da39a3ee5e6b4b0d3255bfef95601890afd80709";

            // Act
            string actualValue = SHA1Encoder.Encode(null);

            // Assert

            Assert.Equal(expectedValue, actualValue);
        }
Esempio n. 3
0
        public void Encode_Returns_Proper_Value()
        {
            //Arrange
            string expectedValue = "a9993e364706816aba3e25717850c26c9cd0d89d";

            // Act
            string actualValue = SHA1Encoder.Encode("abc");

            // Assert

            Assert.Equal(expectedValue, actualValue);
        }
Esempio n. 4
0
        public int CreateUser(User user)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = connectionString;
            conn.Open();

            string query = @"sp_CreateUser";

            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = query;
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@UserName",
                SqlDbType     = System.Data.SqlDbType.VarChar,
                Value         = user.UserName,
                Size          = user.UserName.Length
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@UserPassword",
                SqlDbType     = System.Data.SqlDbType.VarChar,
                Value         = SHA1Encoder.Encode(user.UserPassword),
                Size          = user.UserPassword.Length
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@IsActive",
                SqlDbType     = System.Data.SqlDbType.Bit,
                Value         = user.IsActive
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@RoleID",
                SqlDbType     = System.Data.SqlDbType.Int,
                Value         = user.RoleID
            });

            cmd.Parameters.Add(new SqlParameter
            {
                ParameterName = "@UserID",
                SqlDbType     = System.Data.SqlDbType.Int,
                Direction     = System.Data.ParameterDirection.Output
            });

            cmd.ExecuteNonQuery();

            int userId = Convert.ToInt32(cmd.Parameters["@UserID"].Value);

            cmd.Dispose();
            conn.Close();

            return(userId);
        }