Exemplo n.º 1
0
        public string UpdateRole(string RoleID, string Role)
        {
            try
            {
                if (Context.User.IsInRole("Administrator"))
                {
                    int    myRoleID = Convert.ToInt32(RoleID.Trim());
                    string myRole   = Role.Trim();

                    RoleUpdate myResult = new RolesLogic().UpdateRole(myRoleID, myRole);

                    if (myResult == RoleUpdate.LockedRole)
                    {
                        return("Role is Locked and Cannot be Modified");
                    }
                    else if (myResult == RoleUpdate.SameRole)
                    {
                        return("Role Already Exists");
                    }
                    else
                    {
                        return("");
                    }
                }
                else
                {
                    return("");
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
        public string[] PopulateRoles(string Email)
        {
            try
            {
                if (Context.User.IsInRole("Administrator"))
                {
                    string myEmail = Email.Trim();

                    List <Role> myCurrentRoles = new UsersLogic().RetrieveUserRolesByEmail(myEmail).ToList();
                    List <Role> AllRoles       = new RolesLogic().RetrieveAllRoles().ToList();

                    string CurrentRoleHTML   = "";
                    string AvailableRoleHTML = "";

                    foreach (Role myRole in myCurrentRoles)
                    {
                        CurrentRoleHTML += "<option value=\"" + myRole.Id + "\">" + myRole.Role1 + "</option>";
                    }

                    foreach (Role myRole in myCurrentRoles)
                    {
                        Role ToRemove = AllRoles.SingleOrDefault(r => r.Role1 == myRole.Role1);
                        AllRoles.Remove(ToRemove);
                    }

                    foreach (Role myRole in AllRoles)
                    {
                        AvailableRoleHTML += "<option value=\"" + myRole.Id + "\">" + myRole.Role1 + "</option>";
                    }

                    return(new string[2] {
                        CurrentRoleHTML, AvailableRoleHTML
                    });
                }
                else
                {
                    return(new string[] { "" });
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Occurs when the Role Grid View Selected Index is Changed
        /// Level: External
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvRoles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                lblServerSideError.Text       = "&nbsp;";
                lblServerSideErrorBottom.Text = "";
                btnAdd.Visible    = false;
                btnUpdate.Visible = true;

                Role myRole = new RolesLogic().RetrieveRoleByID(Convert.ToInt32(gvRoles.SelectedValue));

                hdnID.Value  = myRole.Id.ToString();
                txtRole.Text = myRole.Role1;
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Occurs when the Role Grid View Item is Being Deleted
        /// Level: External
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                lblServerSideError.Text = "&nbsp;";

                lblServerSideErrorBottom.Text = "";

                RoleDelete myResult = new RolesLogic().DeleteRole(Convert.ToInt32(e.Keys[0]));

                if (myResult == RoleDelete.LockedRole)
                {
                    //Cant be deleted
                    lblServerSideError.Text = "Role is Locked and Cannot be Deleted";
                }
                else if (myResult == RoleDelete.HasUsers)
                {
                    //bound to users
                    lblServerSideError.Text = "Role is Bound to One or More Users and Cannot be Deleted";
                }
                else
                {
                    gvRoles.SelectedIndex = -1;
                    btnAdd.Visible        = true;
                    btnUpdate.Visible     = false;
                    txtRole.Text          = "";
                    hdnID.Value           = "";
                    gvRoles.DataSource    = new RolesLogic().RetrieveAllRoles();
                    gvRoles.DataBind();
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Exemplo n.º 5
0
 public RoleController(ILogger <RoleController> logger, RolesLogic rolesLogic) : base(logger)
 {
     this._rolesLogic = rolesLogic;
 }