Example #1
0
        static void Main(string[] args)
        {
            WriteLine("---- Application Started -----");


            AppSystem appSystem1 = SecAppManager.GetAppByName("AdWorks");
            AppUser   newUser    = CreateUser("anyone8");
            //AppRole newRole = CreateRole(appSystem1, "role7");
            AppRole newRole = SecRoleManager.GetRoleByName("role7");

            AddUserToRole(newUser, newRole);

            //SecRoleManager.DeleteRoleUsers(newRole);


            //AppRole tmpRole = SecRoleManager.GetRoleByName("Role1");
            //SecRoleManager.DeleteRole(tmpRole);


            //AppSystem appSystem = CreateSystem("AdWorks", "Adventure Works CRUD application.");
            //AppUser newUser = CreateUser("anyone6");
            //AppRole newRole = CreateRole("role6");
            //AddUserToRole(newUser, newRole);

            WriteLine("---- Application Finished -----");
            ReadKey();
        }
Example #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblError.Text    = string.Empty;
            lblSave.Text     = string.Empty;
            lblError.Visible = false;
            lblSave.Visible  = false;
            try {
                using (TransactionScope scope = new TransactionScope()) {
                    SecRole role = SecRoleManager.GetByRoleId(Convert.ToInt32(hdId.Value));
                    role.RoleName        = txtRoleName.Text;
                    role.RoleDescription = txtRoleDescription.Text;
                    role.Status          = ddlStatus.SelectedValue == "1" ? true : false;

                    //role.isClient = cbxIsclient.Checked;

                    SecRoleManager.Save(role);
                    btnCancel_Click(null, null);
                    lblSave.Visible = true;
                    lblSave.Text    = "Record Saved Successfully.";
                    //Label1.Text = "Record Saved";
                    scope.Complete();
                }
            }
            catch (Exception ex) {
                lblError.Visible = true;
                lblError.Text    = "Record Not Saved !!!";
            }
        }
Example #3
0
        private void bindRole()
        {
            List <SecRole> roles = null;

            roles = SecRoleManager.GetAll(roleID);

            CollectionManager.FillCollection(ddlRole, "RoleId", "RoleName", roles);
        }
Example #4
0
        protected void doBind()
        {
            List <SecRole> roles = SecRoleManager.GetRolesManagedByClient(clientID);

            gvClientRoles.DataSource = roles;

            gvClientRoles.DataBind();
        }
Example #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int roleID = Convert.ToInt32(ViewState["RoleID"]);

            SecRole role = null;

            Page.Validate("Role");
            if (!Page.IsValid)
            {
                return;
            }


            clientID = Core.SessionHelper.getClientId();

            if (roleID == 0)
            {
                role          = new SecRole();
                role.ClientID = clientID;
                role.Status   = true;
            }
            else
            {
                role = SecRoleManager.GetByRoleId(roleID);
            }

            if (role != null)
            {
                role.RoleDescription = txtRoleDescription.Text;

                role.RoleName = txtRoleName.Text;

                try {
                    using (TransactionScope scope = new TransactionScope()) {
                        role = SecRoleManager.Save(role);

                        SecRoleModuleManager.deleteRoleModules(clientID, roleID);

                        saveRoleModules(clientID, roleID);

                        saveRoleActions(clientID, roleID);

                        // complete transaction
                        scope.Complete();
                    }

                    // return user to grid
                    showGridPanel();

                    doBind();
                }
                catch (Exception ex) {
                    Core.EmailHelper.emailError(ex);
                }
            }
        }
Example #6
0
        protected void btnShowCreateAccount_Click(object sender, EventArgs e)
        {
            int clientID = SessionHelper.getClientId();

            pnlUserAccount.Visible = true;

            txtUserName.Text = string.Format("{0}.{1}", txtFirstName.Text.Trim().ToLower(), txtLastName.Text.Trim().ToLower());

            // bind client roles
            CollectionManager.FillCollection(ddlClientRoles, "RoleId", "RoleName", SecRoleManager.GetRolesManagedByClient(clientID));
        }
Example #7
0
 public static void DeleteRole()
 {
     try
     {
         AppRole appRole = new AppRole("Role2");
         SecRoleManager.DeleteRole(appRole);
         WriteLine($"{appRole.Name} was deleted.");
     }
     catch (Exception ex)
     {
         WriteLine(ex.Message);
     }
 }
Example #8
0
        protected void gvClientRoles_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int     roleID = Convert.ToInt32(e.CommandArgument);
            SecRole role   = null;

            if (e.CommandName == "DoEdit")
            {
                role = SecRoleManager.GetByRoleId(roleID);

                if (role != null)
                {
                    ViewState["RoleID"] = roleID.ToString();

                    showEditPanel();

                    lbtnSelectAll.Visible = true;

                    txtRoleDescription.Text = role.RoleDescription;
                    txtRoleName.Text        = role.RoleName;

                    if (role.ClientID == null)
                    {
                        // prevent system wide roles from being edited by user
                        txtRoleDescription.Enabled = false;
                        txtRoleName.Enabled        = false;
                    }
                    else
                    {
                        txtRoleDescription.Enabled = true;
                        txtRoleName.Enabled        = true;
                    }

                    bindRoleModules(roleID);

                    bindRoleActions(roleID);
                }
            }
            else if (e.CommandName == "DoDelete")
            {
                role = SecRoleManager.GetByRoleId(roleID);

                if (role != null)
                {
                    role.Status = false;

                    SecRoleManager.Save(role);

                    bindRoleModules(roleID);
                }
            }
        }
Example #9
0
        private void bindRole()
        {
            List <SecRole> roles = null;

            if (roleID == (int)UserRole.Administrator)
            {
                roles = SecRoleManager.GetAll();
            }
            else
            {
                roles = SecRoleManager.GetRolesManagedByClient(clientID);
            }

            CollectionManager.FillCollection(ddlRole, "RoleId", "RoleName", roles);
        }
Example #10
0
        protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //lblError.Text = string.Empty;
            lblError.Visible = false;
            lblSave.Visible  = false;
            if (e.CommandName.Equals("DoEdit"))
            {
                pnlEdit.Enabled = true;
                pnlList.Enabled = false;
                pnlEdit.Visible = true;
                lbnNew.Visible  = false;
                SecRole role = SecRoleManager.GetByRoleId(Convert.ToInt32(e.CommandArgument));
                hdId.Value              = role.RoleId.ToString();
                txtRoleName.Text        = role.RoleName;
                txtRoleDescription.Text = role.RoleDescription;
                ddlStatus.SelectedValue = role.Status == true ? "1" : "0";

                //cbxIsclient.Checked = role.isClient ?? false;

                ddlStatus.Focus();
                btnSave.Enabled = true;
            }
            else if (e.CommandName.Equals("DoDelete"))
            {
                try {
                    using (TransactionScope scope = new TransactionScope()) {
                        pnlList.Enabled = true;
                        pnlEdit.Enabled = false;

                        SecRole role = SecRoleManager.GetByRoleId(Convert.ToInt32(e.CommandArgument));
                        role.Status = false;
                        SecRoleManager.Save(role);
                        scope.Complete();
                    }
                    DoBind();
                    //
                    lblSave.Visible = true;
                    lblSave.Text    = "Role has been deleted.";
                }
                catch (Exception ex) {
                    lblError.Visible = true;
                    lblError.Text    = "Role was not deleted!";
                }
            }
        }
        protected void bindData()
        {
            List <SecRole> roles = SecRoleManager.GetRolesManagedByClient(clientID);

            CollectionManager.FillCollection(ddlRole, "RoleId", "RoleName", roles);
        }
Example #12
0
        protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int     clientID  = SessionHelper.getClientId();
            Contact contact   = null;
            int     id        = string.IsNullOrEmpty(e.CommandArgument.ToString()) ? 0 : Convert.ToInt32(e.CommandArgument);
            int     stateID   = 0;
            int     cityID    = 0;
            int     zipCodeID = 0;

            lblMessage.Text     = string.Empty;
            lblMessage.CssClass = string.Empty;

            if (e.CommandName == "DoEdit")
            {
                ViewState["ContactID"] = id.ToString();

                contact = ContactManager.Get(id);

                if (contact != null)
                {
                    showContactPanel();

                    bindContactTypes();

                    bindStates();

                    if (contact.UserID == null)
                    {
                        btnShowCreateAccount.Visible = true;
                    }
                    else
                    {
                        btnShowCreateAccount.Visible = false;

                        // show current user account for contact
                        pnlUserAccount.Visible = true;

                        txtUserName.Text    = contact.SecUser.UserName;
                        txtUserName.Enabled = false;

                        ddlClientRoles.Enabled = false;

                        // bind client roles
                        CollectionManager.FillCollection(ddlClientRoles, "RoleId", "RoleName", SecRoleManager.GetRolesManagedByClient(clientID));

                        try {
                            ddlClientRoles.SelectedValue = (contact.SecUser.RoleId).ToString();
                        }
                        catch { }

                        // hide create account button
                        this.btnCreateCarrierAccount.Visible = false;
                    }

                    this.txtFirstName.Text      = contact.FirstName;
                    this.txtLastName.Text       = contact.LastName;
                    this.txtContactEmail.Text   = contact.Email;
                    this.txtContactPhone.Text   = contact.Phone;
                    this.txtMobilePhone.Text    = contact.Mobile;
                    this.txtContactTile.Text    = contact.ContactTitle;
                    this.txtDepartmentName.Text = contact.DepartmentName;
                    txtContactFax.Text          = contact.Fax;
                    txtDepartmentName.Text      = contact.DepartmentName;

                    txtAddress1.Text = contact.Address1;
                    txtAddress2.Text = contact.Address2;

                    cbxPrimary.Checked = contact.IsPrimary ?? false;
                    txtContactFax.Text = contact.Fax;

                    stateID = contact.StateID ?? 0;

                    if (stateID > 0)
                    {
                        ddlState.SelectedValue = stateID.ToString();

                        CollectionManager.FillCollection(ddlCity, "CityId", "CityName", City.GetAll(stateID));
                    }

                    cityID = contact.CityID ?? 0;

                    if (cityID > 0)
                    {
                        try {
                            ddlCity.SelectedValue = cityID.ToString();
                        }
                        catch {
                        }

                        CollectionManager.FillCollection(ddlLossZip, "ZipCodeID", "ZipCode", ZipCode.getByCityID(cityID));
                    }
                    zipCodeID = contact.ZipCodeID ?? 0;

                    if (zipCodeID > 0)
                    {
                        try {
                            ddlLossZip.SelectedValue = zipCodeID.ToString();
                        }
                        catch {
                        }
                    }



                    if (contact.CategoryID != null)
                    {
                        try {
                            ddlContactType.SelectedValue = contact.CategoryID.ToString();
                        }
                        catch (Exception ex) {
                            Core.EmailHelper.emailError(ex);
                        }
                    }
                }
            }

            if (e.CommandName == "DoRemove")
            {
                CarrierContactManager.Delete(id);

                bindData(carrierID);
            }
        }
Example #13
0
 private void DoBind()
 {
     gvData.DataSource = SecRoleManager.GetAll();
     gvData.DataBind();
 }
 private void bindDDL()
 {
     // 2013-03-08
     //CollectionManager.FillCollection(ddlRole, "RoleId", "RoleName", SecRoleManager.GetAll().Where(x => (x.RoleId > 2) && x.Status==true));
     CollectionManager.FillCollection(ddlRole, "RoleId", "RoleName", SecRoleManager.GetSystemRoles());
 }