Exemplo n.º 1
0
    public string CRUD_USER(int pType, string pUser, string pPassword, string pEmail, string pProfile, string pCellPhone,
                            string pName, string pLastName, int pDocumentType, string pDni)
    {
        string res = "OK";

        try
        {
            if (pType == TYPE_INSERT)
            {
                //Asociar usuario a tabla de config
                vSQL = @"INSERT INTO CONFIG_USER(UserName,PROFILE_ID,NAME, LAST_NAME, CELL_PHONE,
                                                 DOCUMENT_TYPE_ID,DNI) VALUES('" + pUser + "'," + pProfile + ",'" + pName +
                       "','" + pLastName + "','" + pCellPhone +
                       "'," + pDocumentType + ",'" + pDni + "')";
                Data.OPERATIONS(vSQL);

                Membership.CreateUser(pUser, pPassword, pEmail);
            }
            else if (pType == TYPE_UPDATE)
            {
                MembershipUser user = Membership.GetUser(pUser);
                res = user.ResetPassword();
            }
            else if (pType == TYPE_DELETE)
            {
                vSQL = "DELETE FROM CONFIG_USER WHERE UserName = '******'";
                Data.OPERATIONS(vSQL);

                Membership.DeleteUser(pUser);
            }
            else if (pType == TYPE_LOCK)
            {
                vSQL = @"UPDATE aspnet_Membership SET IsLockedOut = 1 WHERE UserId = '" + pUser + "'";
                Data.OPERATIONS(vSQL);
            }
            else if (pType == TYPE_UNLOCK)
            {
                vSQL = @"UPDATE aspnet_Membership SET IsLockedOut = 0 WHERE UserId = '" + pUser + "'";
                Data.OPERATIONS(vSQL);
            }
            else if (pType == TYPE_CHANGE_GENERALDATA)
            {
                vSQL = @"DECLARE @_userId NVARCHAR(250) 

                        SELECT @_userId = u.UserId
                        FROM dbo.aspnet_Users u
                        WHERE u.UserName = '******'

                        UPDATE  dbo.aspnet_Membership 
                        SET Email = '" + pEmail + @"'
                        WHERE UserId = @_userId

                        UPDATE dbo.CONFIG_USER 
                        SET PROFILE_ID = " + pProfile + @",
                        [NAME] = '" + pName + @"',
                        [LAST_NAME] = '" + pLastName + @"',
                        [CELL_PHONE] = '" + pCellPhone + @"',
                        [DOCUMENT_TYPE_ID] = " + pDocumentType + @",
                        [DNI] = '" + pDni + @"'
                        WHERE UserName = '******'";
                Data.OPERATIONS(vSQL);
            }
        }
        catch (Exception ex)
        {
            if (pType == TYPE_INSERT)
            {
                vSQL = "DELETE FROM CONFIG_USER WHERE UserName = '******'";
                Data.OPERATIONS(vSQL);
            }

            res = ex.Message;
        }

        return(res);
    }