Example #1
0
        // ---- funciones-------

        public bool CreateUser(UserBE userBE)
        {
            bool registrado = false;

            try
            {
                using (SqlConnection cnx = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("usp_CreationUser", cnx);
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.CommandTimeout = 600;//6 segundos

                    SQLHelper.AddParam(ref cmd, "@user_role", ParameterDirection.Input, SqlDbType.Int, userBE.User_Role);
                    SQLHelper.AddParam(ref cmd, "@username", ParameterDirection.Input, SqlDbType.VarChar, userBE.username);
                    SQLHelper.AddParam(ref cmd, "@name", ParameterDirection.Input, SqlDbType.VarChar, userBE.Name);
                    SQLHelper.AddParam(ref cmd, "@lastname", ParameterDirection.Input, SqlDbType.VarChar, userBE.LastName);
                    SQLHelper.AddParam(ref cmd, "@email", ParameterDirection.Input, SqlDbType.VarChar, userBE.Email);
                    SQLHelper.AddParam(ref cmd, "@phonenumber", ParameterDirection.Input, SqlDbType.VarChar, userBE.PhoneNumber);
                    SQLHelper.AddParam(ref cmd, "@userid", ParameterDirection.Input, SqlDbType.VarChar, userBE.IdUser);

                    //Encriptar contrasenia
                    var pass = PasswordSC.PasswordEncriptarSHA512(userBE.Password);
                    SQLHelper.AddParam(ref cmd, "@password", ParameterDirection.Input, SqlDbType.VarChar, pass);

                    SQLHelper.AddParam(ref cmd, "@dni", ParameterDirection.Input, SqlDbType.VarChar, userBE.DNI);
                    SQLHelper.AddParam(ref cmd, "@birthday", ParameterDirection.Input, SqlDbType.DateTime, userBE.Birthday);
                    SQLHelper.AddParam(ref cmd, "@status", ParameterDirection.Input, SqlDbType.Char, userBE.Status);
                    SQLHelper.AddParam(ref cmd, "@gener", ParameterDirection.Input, SqlDbType.Char, userBE.Gener);
                    //para recibir un parametro de respuesta del storedprocedure
                    //cmd.Parameters.Add("@userId", SqlDbType.UniqueIdentifier).Direction = ParameterDirection.Output;

                    //abrimos la conexion
                    cnx.Open();
                    //ejecutamos el query
                    cmd.ExecuteNonQuery();

                    //obtenemos el valor de respuesta despues de recibir el output del stored procedure
                    //var userid = cmd.Parameters["@userId"].ToString();

                    registrado = true;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(registrado);
        }
Example #2
0
        public bool UpdateUser(UserBE userupdate)
        {
            bool update = false;

            SqlConnection cn  = new SqlConnection(connectionString);
            SqlCommand    cmd = cn.CreateCommand();

            cmd.CommandText = "usp_Update_User";
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                SQLHelper.AddParam(ref cmd, "@userid", ParameterDirection.Input, SqlDbType.UniqueIdentifier, userupdate.IdUser);
                SQLHelper.AddParam(ref cmd, "@user_role", ParameterDirection.Input, SqlDbType.Int, userupdate.User_Role);
                SQLHelper.AddParam(ref cmd, "@username", ParameterDirection.Input, SqlDbType.VarChar, userupdate.username);
                SQLHelper.AddParam(ref cmd, "@name", ParameterDirection.Input, SqlDbType.VarChar, userupdate.Name);
                SQLHelper.AddParam(ref cmd, "@lastname", ParameterDirection.Input, SqlDbType.VarChar, userupdate.LastName);
                SQLHelper.AddParam(ref cmd, "@email", ParameterDirection.Input, SqlDbType.VarChar, userupdate.Email);
                SQLHelper.AddParam(ref cmd, "@phonenumber", ParameterDirection.Input, SqlDbType.VarChar, userupdate.PhoneNumber);
                SQLHelper.AddParam(ref cmd, "@password", ParameterDirection.Input, SqlDbType.VarChar, userupdate.Password);
                SQLHelper.AddParam(ref cmd, "@dni", ParameterDirection.Input, SqlDbType.VarChar, userupdate.DNI);
                SQLHelper.AddParam(ref cmd, "@birthday", ParameterDirection.Input, SqlDbType.DateTime, userupdate.Birthday);
                SQLHelper.AddParam(ref cmd, "@status", ParameterDirection.Input, SqlDbType.Char, userupdate.Status);

                cn.Open();
                cmd.ExecuteNonQuery();
                update = true;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
                cn.Dispose();
                cmd.Dispose();
            }

            return(update);
        }