Ejemplo n.º 1
0
        /// <summary>
        /// Assign New Role to Current User.
        /// </summary>
        /// <param name="AD_Role_ID"></param>
        /// <param name="AD_User_ID"></param>
        private void CreateNewUserRole(int AD_Role_ID, int AD_User_ID)
        {
            MUserRoles role = new MUserRoles(ctx, 0, null);

            role.SetAD_Org_ID(ctx.GetAD_Org_ID());
            role.SetAD_Client_ID(ctx.GetAD_Client_ID());
            role.SetAD_User_ID(AD_User_ID);
            role.SetAD_Role_ID(AD_Role_ID);
            role.Save();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Name.Value))
            {
                return;
            }
            HttpRequest q    = Request;
            string      lang = q.QueryString["lang"];

            usernotSaved    = Msg.GetMsg(lang, "VIS_ErrorSavingUser");
            Button1.Enabled = false;
            int AD_Client_ID = 0;
            int AD_Org_ID    = 0;

            int     inviteID = Convert.ToInt32(SecureEngine.Decrypt(q.QueryString["inviteID"]));
            String  sql      = "SELECT * FROM AD_InviteUser WHERE AD_InviteUser_ID=" + inviteID;
            DataSet dsIUser  = DB.ExecuteDataset(sql);

            if (dsIUser != null && dsIUser.Tables[0].Rows.Count > 0)
            {
                AD_Org_ID    = Convert.ToInt32(dsIUser.Tables[0].Rows[0]["AD_Org_ID"]);
                AD_Client_ID = Convert.ToInt32(dsIUser.Tables[0].Rows[0]["AD_Client_ID"]);
            }

            sql = "SELECT AD_Role_ID FROM ad_inviteuser_role WHERE AD_InviteUser_ID= " + inviteID;
            DataSet ds = DB.ExecuteDataset(sql);



            Ctx ctx = new Ctx();

            ctx.SetAD_Client_ID(AD_Client_ID);
            ctx.SetAD_Org_ID(AD_Org_ID);


            MUser user = new MUser(ctx, 0, null);

            user.SetAD_Client_ID(AD_Client_ID);
            user.SetAD_Org_ID(AD_Org_ID);
            user.SetIsLoginUser(true);
            user.SetName(Name.Value);
            user.SetValue(userIDs.Value);
            user.SetEMail(email.Value);
            user.SetPassword(passwords.Value);
            user.SetMobile(mobile.Value);
            if (user.Save())
            {
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        MUserRoles uRoles = new MUserRoles(ctx, user.GetAD_User_ID(), Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Role_ID"]), null);
                        uRoles.SetAD_Client_ID(AD_Client_ID);
                        uRoles.SetAD_Org_ID(AD_Org_ID);
                        uRoles.Save();
                    }
                }

                sendMail.Visible = true;
                Name.Value       = "";
                userIDs.Value    = "";
                email.Value      = "";
                passwords.Value  = "";
                mobile.Value     = "";
            }
            else
            {
                Button1.Enabled    = true;
                sendMail.InnerText = usernotSaved;
                sendMail.Visible   = true;
            }
        }