Beispiel #1
0
//-------------------------------------------------------------------------------------------
        protected void FormView1_DataBound(object sender, EventArgs e)
        {
            ICustomTypeDescriptor descriptor = FormView1.DataItem as ICustomTypeDescriptor;

            if (descriptor != null)
            {
                EntityObject entityObject = (EntityObject)descriptor.GetPropertyOwner(null);

                string[] userRoles = GetUserRoles();

                DataAccess readPermissions = entityObject.ReadPermissions();
                FormView1.FindControlR <Literal>("Permissions").Text = "Accessible to: " + String.Join(", ", readPermissions.AllowedRoles);

                DataAccess deletePermissions = entityObject.DeletePermissions();
                DeleteItem.Visible = (deletePermissions.HasMatchingRole(userRoles));
                DeleteItem.ToolTip = "Accessible to: " + String.Join(", ", deletePermissions.AllowedRoles);

                DataAccess updatePermissions = entityObject.UpdatePermissions();
                bool       canUpdate         = updatePermissions.HasAnyRole(userRoles);

                DataAccess insertPermissions = entityObject.GetType().InsertPermissions();
                bool       canInsert         = insertPermissions.HasAnyRole(userRoles);

                if (FormView1.CurrentMode == FormViewMode.ReadOnly)
                {
                    BeginEdit.Visible  = canUpdate;
                    SaveEdit.Visible   = false;
                    CancelEdit.Visible = false;
                }

                if (FormView1.CurrentMode == FormViewMode.Insert)
                {
                    SaveEdit.Visible   = canInsert;
                    BeginEdit.Visible  = false;
                    DeleteItem.Visible = false;      // item doesn't exist so you can't delete it
                }

                if (canUpdate && FormView1.CurrentMode == FormViewMode.Edit)
                {
                    if (updatePermissions.HasAnyRole(userRoles))
                    {
                        EditOptions.Visible = true;
                        BeginEdit.Visible   = false;
                        SaveEdit.Visible    = true;
                        CancelEdit.Visible  = true;
                        UpdatePanel1.FindControlR <LinkButton>("BeginEdit").Visible  = false;
                        UpdatePanel1.FindControlR <LinkButton>("CancelEdit").Visible = true;
                        DeleteItem.Visible = false;
                    }
                    BeginEdit.ToolTip = "Accessible to: " + String.Join(", ", updatePermissions.AllowedRoles);
                }
            }
        }
Beispiel #2
0
//-------------------------------------------------------------------------------------------
        protected void Delete_Link(object sender, EventArgs e)
        {
            FormView1.DataBind();

            string[] userRoles = GetUserRoles();

            ICustomTypeDescriptor descriptor        = FormView1.DataItem as ICustomTypeDescriptor;
            EntityObject          entityObject      = (EntityObject)descriptor.GetPropertyOwner(null);
            DataAccess            deletePermissions = entityObject.DeletePermissions();

            if (deletePermissions.HasMatchingRole(userRoles))
            {
                FormView1.DeleteItem();
            }
        }