/// <summary>
 /// Retrieve category node hierarchy from the database.
 /// </summary>
 /// <returns></returns>
 private IList <CategoryNode> GetTreeHierarchy()
 {
     using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
     {
         return(dataAccess.GetRootCategoryNodesWithHierarchy().ToList());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Saves associations for the subject entity.
        /// </summary>
        /// <returns>A Boolean value indicating success of operation.</returns>
        public override bool SaveAssociation()
        {
            bool result = false;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
            {
                AuthorizeResourcesBeforeSave <Tag>(dataAccess);

                switch (ObjectType)
                {
                case ObjectEntityType.Tag:
                    result = dataAccess.SaveScholarlyWorkItemTagAssociation(SubjectItemId,
                                                                            DestinationList as List <Tag>);
                    base.RefreshDataSource();
                    break;

                case ObjectEntityType.CategoryNode:
                    result = dataAccess.SaveScholarlyItemCategoryAssociation(SubjectItemId,
                                                                             DestinationList as List <CategoryNode>, AuthenticatedToken, Constants.PermissionRequiredForAssociation);
                    base.RefreshDataSource();
                    break;

                default:
                    break;
                }
            }
            return(result);
        }
 private bool HasAccess(Guid categoryId)
 {
     using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
     {
         return(dataAccess.AuthorizeResource <CategoryNode>(AuthenticatedToken, Constants.PermissionRequiredForAssociation, categoryId, false));
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates list of properties of selected ResourceType
        /// </summary>
        /// <returns>List of properties of Resource</returns>
        private Collection <ScalarProperty> GetResourceProperties()
        {
            Collection <ScalarProperty> scalarProperties = null;

            if (!this.DesignMode)
            {
                using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
                {
                    scalarProperties = dataAccess.GetScalarProperties(this.Page.Cache, EntityType);
                }
            }

            if (scalarProperties != null)
            {
                //Since ID property and properties having data type is binary should not be exposed, remove it from the property list
                List <ScalarProperty> removeProperties = scalarProperties.Where(
                    property => property.Name.Equals(_PropertyId,
                                                     StringComparison.OrdinalIgnoreCase) || property.DataType == DataTypes.Binary).ToList();

                foreach (ScalarProperty property in removeProperties)
                {
                    scalarProperties.Remove(property);
                }
            }

            return(scalarProperties);
        }
    private void InitializeFieldVariables()
    {
        if (ResourceId != Guid.Empty)
        {
            isEditMode = true;
            ButtonSimilarMatch.Visible     = false;
            resourceProperties.ControlMode = ResourcePropertiesOperationMode.Edit;
            resourceProperties.ResourceId  = ResourceId;
        }
        else
        {
            resourceProperties.ControlMode = ResourcePropertiesOperationMode.Add;
            using (ResourceDataAccess dataAccess = new ResourceDataAccess())
            {
                ResourceType resTypeObj = dataAccess.GetResourceType(typeName);

                if (resTypeObj != null)
                {
                    resourceProperties.ResourceType = resTypeObj.Name;
                }
                else
                {
                    HideResourcePropertyControl(Resources.Resources.InvalidResourceType);
                    return;
                }
            }
        }

        // Handle scenario which is "a resource deleted by one user and another user operating on the resource".
        using (ResourceDataAccess resDataAccess = new ResourceDataAccess())
        {
            if (isEditMode)
            {
                Resource resource = resDataAccess.GetResource(ResourceId);

                if (resource == null)
                {
                    this.HideResourcePropertyControl(Resources.Resources.ResourceNotFound);
                    this._isResourceExist = false;
                    return;
                }

                typeName   = resource.GetType().Name;
                Page.Title = Resources.Resources.Edit + Blank_Space + Utility.FitString(Utility.UpdateEmptyTitle(resource.Title),
                                                                                        _titleLength) + "(" + typeName + ")";
            }
            else
            {
                Page.Title = Resources.Resources.Create + Blank_Space + Utility.FitString(typeName, _titleLength);
            }
        }

        resourceProperties.ResourceType = typeName;
        resourceProperties.Title        = string.Format(CultureInfo.InvariantCulture,
                                                        Resources.Resources.ResourceLabelResourcePropertiesText, typeName);
        resourceProperties.ValidationRequired = true;
        ButtonSimilarMatch.ValidationGroup    = _createResourceValidationGroup;
        SubmitButton.ValidationGroup          = _createResourceValidationGroup;
        resourceProperties.ValidationGroup    = _createResourceValidationGroup;
    }
Beispiel #6
0
    /// <summary>
    /// Manage the group information section while updating group information.
    /// </summary>
    private void ManageGroupSection()
    {
        if (!string.IsNullOrEmpty(Id))
        {
            txtGroupName.Enabled = false;
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
            {
                //Populate group info on UI
                Group groupObject = (Group)dataAccess.GetResource(new Guid(Id));

                if (groupObject == null)
                {
                    return;
                }

                groupInformation = dataAccess.GetGroup(groupObject.GroupName);

                if (!Page.IsPostBack)
                {
                    txtTitle.Text       = groupInformation.Title;
                    txtGroupName.Text   = groupInformation.GroupName;
                    txtDescription.Text = groupInformation.Description;
                    txtUri.Text         = groupInformation.Uri;
                }
            }
        }
    }
Beispiel #7
0
        /// <summary>
        /// Creates the controls required for association.
        /// </summary>
        private void CreatePredicateAndObjectControls()
        {
            _predicateLabel = CreateLabel(GlobalResource.AssociationPredicateLabel, _predicateLabelId);

            List <NavigationProperty> navigationalProperties = null;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
            {
                navigationalProperties = dataAccess.GetNavigationalProperties(this.Page.Cache,
                                                                              typeName).OrderBy(property => property.Name).ToList();
            }


            _predicateDropDownList = CreateDropDownList(null, _predicateDataTextField,
                                                        _predicateDataValueField, true, _predicateDropDownId);

            foreach (NavigationProperty property in navigationalProperties)
            {
                _predicateDropDownList.Items.Add(new ListItem(property.Name, property.Id.ToString()));
            }

            if (!string.IsNullOrEmpty(SelectedPredicateId))
            {
                _predicateDropDownList.SelectedValue = SelectedPredicateId;
            }

            _predicateDropDownList.SelectedIndexChanged += new EventHandler
                                                               (PredicateTypeDropDownList_SelectedIndexChanged);

            _objectTypeLabel = CreateLabel(null, _objectLabelId);

            _objectTypeDropDownList = CreateDropDownList(null, "Name", "FullName", true, _ObjectDropDownId);
            _objectTypeDropDownList.SelectedIndexChanged += new EventHandler
                                                                (ObjectTypeDropDownList_SelectedIndexChanged);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Set authenticatedToken to resource search control
        ResourceDetailView.AuthenticatedToken = Session[Constants.AuthenticationTokenKey] as AuthenticatedToken;

        if (!IsPostBack)
        {
            DeleteButton.Attributes.Add("OnClick", "javascript: return confirm('" + Resources.Resources.ConfirmDeleteResource + "');");
            ResourceDetailView.ResourceId = ResourceId;

            if (ResourceDetailView.ResourceId != Guid.Empty && ResourceDetailView.AuthenticatedToken != null)
            {
                //Check whether use is authorize to delete the resource. If not then make Delete buttion invisible.
                using (ResourceDataAccess dataAccess = new ResourceDataAccess())
                {
                    if (!dataAccess.AuthorizeUser(ResourceDetailView.AuthenticatedToken, UserResourcePermissions.Delete, ResourceDetailView.ResourceId))
                    {
                        DeleteButton.Visible = false;
                    }
                }
            }
            else
            {
                DeleteButton.Visible = false;
            }
        }
    }
Beispiel #9
0
 void ObjectTypeDropDownList_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
     {
         FilterCriteriaGrid.EntityType = _objectTypeDropDownList.SelectedValue;
     }
 }
Beispiel #10
0
 protected void LoginButton_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(UserNameTextBox.Text.Trim()) && !string.IsNullOrEmpty(PasswordTextBox.Text.Trim()))
     {
         using (ResourceDataAccess dataAccess = new ResourceDataAccess())
         {
             //Authenticate User
             AuthenticatedToken authenticatedToken = dataAccess.Authenticate(UserNameTextBox.Text, PasswordTextBox.Text);
             if (authenticatedToken == null)
             {
                 ErrorMessageLabel.Text = Resources.Resources.MsgLoginFailed;
             }
             else
             {
                 Session[Constants.AuthenticationTokenKey] = authenticatedToken;
                 LoginPanel.Visible     = false;
                 LogoutPanel.Visible    = true;
                 LoggedInUserLabel.Text = String.Format(CultureInfo.CurrentCulture, Resources.Resources.MsgWelcomeUser, UserNameTextBox.Text);
                 PasswordTextBox.Text   = string.Empty;
                 if (Request.QueryString[Constants.URL] != null)
                 {
                     Response.Redirect(Request.QueryString[Constants.URL]);
                 }
                 else
                 {
                     Response.Redirect(Request.Url.ToString());
                 }
             }
         }
     }
 }
        private void AddBibTexLinks()
        {
            using (ResourceDataAccess resourceDAL = new ResourceDataAccess(this.CreateContext()))
            {
                if (!IsSecurityAwareControl || (UserPermissions != null && UserPermissions.Contains(UserResourcePermissions.Read)))
                {
                    ScholarlyWork scholarlyWorkObj = (ScholarlyWork)resourceDAL.GetScholarlyWorkWithCitedScholarlyWorks(SubjectResource.Id);

                    if (scholarlyWorkObj != null && scholarlyWorkObj.Cites.Count > 0)
                    {
                        BibTexExportLink.Visible = true;
                    }
                    else
                    {
                        BibTexExportLink.Visible = false;
                    }
                }

                if (!IsSecurityAwareControl || (UserPermissions != null && UserPermissions.Contains(UserResourcePermissions.Update)))
                {
                    BibTexImportLink.Visible = true;
                }
                else
                {
                    BibTexImportLink.Visible = false;
                }

                SeperatorLabel.Visible = (BibTexExportLink.Visible == false || BibTexImportLink.Visible == false) ? false : true;
            }

            this.Controls.Add(BibTexPanel);
        }
Beispiel #12
0
        private void UpdateMostActiveAuthorsView()
        {
            IList <Resource> dataSource = null;

            if (!IsSecurityAwareControl)
            {
                using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
                {
                    dataSource = dataAccess.GetTopAuthors(null, PageSize).Select(tuple => tuple as Resource).ToList();
                }
            }
            else
            {
                if (this.AuthenticatedToken != null)
                {
                    using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
                    {
                        dataSource = dataAccess.GetTopAuthors(this.AuthenticatedToken, PageSize).Select(tuple => tuple as Resource).ToList();
                    }
                }
            }
            ResourceListView.DataSource.Clear();
            foreach (Resource resource in dataSource)
            {
                ResourceListView.DataSource.Add(resource);
            }

            ResourceListView.DataBind();
        }
Beispiel #13
0
    protected void btnGrantAccess_Click(object sender, EventArgs e)
    {
        bool result = false;
        List <PermissionMap> permissionList = new List <PermissionMap>();

        foreach (GridViewRow item in grdGlobalPermission.Rows)
        {
            PermissionMap pm = new PermissionMap();
            pm.Permission = ((Label)item.FindControl("lblPermission")).Text;
            pm.Allow      = ((CheckBox)item.FindControl("chkGrantPermission")).Checked;
            pm.Deny       = ((CheckBox)item.FindControl("chkRevokePermission")).Checked;
            permissionList.Add(pm);
        }
        using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
        {
            result = dataAccess.SetCreatePremissions(permissionList[0], Id.ToString(), userToken);
        }

        if (result)
        {
            Utility.ShowMessage(lblErrorGlobalPermission, Resources.Resources.PermissionGranted, false);
        }
        else
        {
            Utility.ShowMessage(lblErrorGlobalPermission, Resources.Resources.FailToGrantPermission, false);
        }
        lblErrorGlobalPermission.Visible = true;
    }
Beispiel #14
0
    protected void btnGrantAccess_Click(object sender, EventArgs e)
    {
        List <PermissionMap> permissionList = new List <PermissionMap>();

        foreach (GridViewRow item in grdVwPermission.Rows)
        {
            PermissionMap pm = new PermissionMap();
            pm.Permission = ((Label)item.FindControl("lblPermission")).Text;
            pm.Allow      = ((CheckBox)item.FindControl("chkGrantPermission")).Checked;
            pm.Deny       = ((CheckBox)item.FindControl("chkRevokePermission")).Checked;
            permissionList.Add(pm);
        }

        bool result = false;

        using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
        {
            result = dataAccess.SetPermissionToResource(ResourceId, permissionList,
                                                        UserOrGroupId,
                                                        userToken);
        }

        if (PermissionGranted != null)
        {
            PermissionGranted(sender, new GrantEventArgs(result));
        }
    }
Beispiel #15
0
        private void UpdateRecentlyModifiedResourceView()
        {
            IList <Resource> dataSource = null;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
            {
                if (!IsSecurityAwareControl)
                {
                    dataSource = dataAccess.GetLatestModifiedResources(null, PageSize);
                }
                else
                {
                    if (this.AuthenticatedToken != null)
                    {
                        dataSource = dataAccess.GetLatestModifiedResources(this.AuthenticatedToken, this.PageSize);
                        GetPermissions(this.AuthenticatedToken, dataSource);
                    }
                }
            }
            ResourceListView.DataSource.Clear();
            foreach (Resource resource in dataSource)
            {
                ResourceListView.DataSource.Add(resource);
            }

            ResourceListView.SortDirection  = SortDirection.Descending;
            ResourceListView.SortExpression = _dateModifiedProperty;
            ResourceListView.ShowDate       = DateType.DateModified;
            ResourceListView.SortDataSource(SortDirection.Descending, _dateModifiedProperty);
            ResourceListView.DataBind();
        }
Beispiel #16
0
        /// <summary>
        /// Adds columns to be displayed in the column collection.
        /// </summary>
        protected override void AddDisplayColumns()
        {
            if (!this.DesignMode)
            {
                Collection <ScalarProperty> propertyList = null;
                using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
                {
                    propertyList = dataAccess.GetScalarProperties(this.Page.Cache, EntityType);
                }

                //Add View Column.
                if (!string.IsNullOrEmpty(ViewColumn))
                {
                    AddViewColumn(propertyList);
                }

                //If user column list is been provided.
                if (DisplayColumns != null && DisplayColumns.Count > 0)
                {
                    AddCustomColumns(propertyList);
                }
                else
                {
                    //Add default columns based on Resource type
                    AddDefaultColumns(propertyList);
                }
            }
            else
            {
                //Add View Column
                base.AddViewColumn(GlobalResource.TitleText, GlobalResource.TitleText,
                                   GlobalResource.TitleText);
            }
        }
        /// <summary>
        /// Add new claims to the resource manager
        /// </summary>
        /// <param name="id">Resource Id</param>
        /// <param name="name">Claim Name</param>
        /// <returns><![CDATA[ (ResourceClaimVm Claim, bool IsSuccess,String Message) ]]></returns>
        public (ResourceClaimVm Claim, bool IsSuccess, String Message) AddClaim(int id, string name)
        {
            try
            {
                // Check if the claim already exists
                var dbCheck = ResourceDataAccess.ResourceClaim.Find(f => f.ResourceId == id && f.ClaimName.ToLower() == name.ToLower());
                if (dbCheck != null)
                {
                    return(null, false, ResourceManagerMessages.Error.CLAIM_ADD_ALREADY_EXISTS);
                }


                var dbClaim = (new ResourceClaimVm()
                {
                    ClaimName = name
                }).ToEntityCreate(id);
                dbClaim = ResourceDataAccess.ResourceClaim.Create(dbClaim);

                ResourceDataAccess.Save();

                return(new ResourceClaimVm(dbClaim), true, ResourceManagerMessages.Success.CLAIM_CREATED);
            }
            catch (DbEntityValidationException ex)
            {
#if (DEBUG)
                // for debuging entity framework
                foreach (var error in ex.EntityValidationErrors.SelectMany(valError => valError.ValidationErrors))
                {
                    Console.WriteLine(error.ErrorMessage);
                }
#endif
                throw;
            }
        }
 /// <summary>
 /// Gets subject resource.
 /// </summary>
 /// <returns>Subject resource.</returns>
 protected ScholarlyWorkItem GetScholarlyWorkItem()
 {
     using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
     {
         ScholarlyWorkItem item;
         if (IsSecurityAwareControl)
         {
             if (AuthenticatedToken != null)
             {
                 item = dataAccess.GetScholarlyWorkItem(ResourceItemId, AuthenticatedToken, UserResourcePermissions.Update);
             }
             else
             {
                 throw new UnauthorizedAccessException(string.Format(CultureInfo.CurrentCulture,
                                                                     GlobalResource.UnauthorizedAccessException, UserResourcePermissions.Update));
             }
         }
         else
         {
             item = dataAccess.GetScholarlyWorkItem(ResourceItemId, null, UserResourcePermissions.Update);
         }
         item.CategoryNodes.Load();
         return(item);
     }
 }
    protected void CreateNewResource_Click(object sender, EventArgs e)
    {
        if (this._resource == null)
        {
            LabelRecordNotMatch.Text    = Resources.Resources.SimilarityMatchResourceSaved;
            ButtonCreateNew.Visible     = false;
            LabelRecordNotMatch.Visible = true;
            return;
        }
        string typeName = this._resource.GetType().Name;

        //Add resource to database
        using (ResourceDataAccess resourceDAL = new ResourceDataAccess())
        {
            resourceDAL.AddResource(this._resource);
            GrantOwnership(this._resource.Id);
        }

        //Do clean up and redirect.
        Session.Remove(this._guid.ToString("D"));
        this.ButtonCreateNew.Visible = false;
        this.PanelResultGrid.Visible = false;

        errorMessage.Text = string.Format(CultureInfo.CurrentCulture,
                                          Resources.Resources.AlertResourceAdded,
                                          typeName, Utility.GetLinkTag(Resources.Resources.ManageResourceLink + _resource.Id,
                                                                       Utility.FitString(_resource.Title, 40)));
        errorMessage.Visible = true;
    }
Beispiel #20
0
        private void RefreshObjectTypeDropDown()
        {
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
            {
                NavigationProperty property = dataAccess.GetNavigationProperty(this.Page.Cache
                                                                               , typeName, _predicateDropDownList.SelectedItem.Text);

                string resTypeName = string.Empty;

                if (property.Direction == AssociationEndType.Subject)
                {
                    resTypeName = property.Association.ObjectNavigationProperty.Parent.Name;
                }
                else if (property.Direction == AssociationEndType.Object)
                {
                    resTypeName = property.Association.SubjectNavigationProperty.Parent.Name;
                }
                List <ResourceType> resourceTypeList = dataAccess.GetResourceTypeList
                                                           (resTypeName)
                                                       .OrderBy(res => res.Name).ToList();

                _objectTypeDropDownList.DataSource = resourceTypeList;
                _objectTypeDropDownList.DataBind();
                FilterCriteriaGrid.EntityType = _objectTypeDropDownList.SelectedValue;
            }
        }
Beispiel #21
0
        private List <ResourceType> GetResourceTypeList()
        {
            List <ResourceType> resTypeList = null;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
            {
                resTypeList = dataAccess.GetResourceTypes().ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Identity").ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Group").ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "CategoryNode").ToList();
            }
            if (string.IsNullOrEmpty(ResourceHierarchy))
            {
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Tag").ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "CategoryNode").ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Contact").ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Person").ToList();
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Organization").ToList();
            }
            else
            {
                resTypeList = resTypeList.Where(tuple => tuple.Name != "Tag").ToList();
            }
            return(resTypeList);
        }
Beispiel #22
0
 /// <summary>
 /// Returns list of latest added resources
 /// </summary>
 /// <param name="pageSize">Maximum No. of records to be fetched</param>
 /// <param name="token">Authenticated token</param>
 /// <returns></returns>
 public static List <Contact> GetTopAuthors(AuthenticatedToken token, int pageSize)
 {
     using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
     {
         return(dataAccess.GetTopAuthors(token, pageSize));
     }
 }
Beispiel #23
0
    private string GetActiveTab()
    {
        string activeTab = Convert.ToString(Request.QueryString[_activeTabKey]);

        if (!string.IsNullOrEmpty(activeTab))
        {
            if (!IsValidTab(activeTab))
            {
                throw new ArgumentException(Resources.Resources.MsgInvalidTab);
            }
            if (!IsEditMode)
            {
                if (SelectedResourceType == null)
                {
                    activeTab = null;
                }
                else if (activeTab != Constants.MetadataTab)
                {
                    activeTab = Constants.MetadataTab;
                }
            }
            else
            {
                if ((SummaryTab.Visible &&
                     (activeTab.Equals(Constants.MetadataTab, StringComparison.OrdinalIgnoreCase) && !MetadataTab.Visible) ||
                     (activeTab.Equals(Constants.AssociationTab, StringComparison.OrdinalIgnoreCase) && !AssociationsTab.Visible) ||
                     (activeTab.Equals(Constants.CategoriesTab, StringComparison.OrdinalIgnoreCase) && !CategoriesTab.Visible) ||
                     (activeTab.Equals(Constants.TagsTab, StringComparison.OrdinalIgnoreCase) && !TagsTab.Visible) ||
                     (activeTab.Equals(Constants.ChangeHistoryTab, StringComparison.OrdinalIgnoreCase) && !ChangeHistoryTab.Visible) ||
                     (activeTab.Equals(Constants.ResourcePermissionsTab, StringComparison.OrdinalIgnoreCase) && !ResourcePermissionsTab.Visible)))
                {
                    activeTab = Constants.SummaryTab;
                }
            }
        }
        else
        {
            if (IsEditMode)
            {
                activeTab = Constants.SummaryTab;
            }
            else
            {
                if (!string.IsNullOrEmpty(SelectedResourceType))
                {
                    using (ResourceDataAccess dataAccess = new ResourceDataAccess())
                    {
                        int childTypeCount = dataAccess.GetChildResourceTypesCount(SelectedResourceType);
                        if (childTypeCount == 0)
                        {
                            activeTab = Constants.MetadataTab;
                        }
                    }
                }
            }
        }

        return(activeTab);
    }
    /// <summary>
    /// Delete given resource from database.
    /// </summary>
    /// <param name="sender">sender</param>
    /// <param name="e">Event Args</param>
    protected void DeleteButton_OnClick(object sender, EventArgs e)
    {
        using (ResourceDataAccess dataAccess = new ResourceDataAccess())
        {
            if (ResourceDetailView.ResourceId != Guid.Empty)
            {
                Resource resource     = dataAccess.GetResource(ResourceDetailView.ResourceId);
                bool     isAuthorized = resource is CategoryNode?
                                        dataAccess.AuthorizeUserForDeletePermissionOnCategory(ResourceDetailView.AuthenticatedToken, resource.Id) :
                                            dataAccess.AuthorizeUser(ResourceDetailView.AuthenticatedToken, UserResourcePermissions.Delete, resource.Id);

                if (isAuthorized)
                {
                    bool isDeleted = resource is CategoryNode?
                                     dataAccess.DeleteCategoryNodeWithHierarchy(ResourceDetailView.ResourceId) :
                                         dataAccess.DeleteResource(ResourceDetailView.ResourceId);

                    //Delete resource
                    if (isDeleted)
                    {
                        DeleteButton.Visible       = false;
                        ResourceDetailView.Visible = false;
                        //Show Delete successful message
                        MessageLabel.ForeColor = System.Drawing.Color.Black;
                        MessageLabel.Text      = Resources.Resources.AlertRecordDelerted;
                        if (OnSuccessfulDelete != null)
                        {
                            OnSuccessfulDelete(this, new EventArgs());
                        }
                    }
                    else
                    {
                        //Show delete failure message
                        MessageLabel.ForeColor = System.Drawing.Color.Red;
                        MessageLabel.Text      = Resources.Resources.AlertResourceDelertedError;
                    }
                }
                else
                {
                    //Show delete failure message
                    MessageLabel.ForeColor = System.Drawing.Color.Red;
                    if (resource is CategoryNode)
                    {
                        MessageLabel.Text = Resources.Resources.MsgUnauthorizeAccessDeleteCategory;
                    }
                    else
                    {
                        MessageLabel.Text = string.Format(CultureInfo.InvariantCulture, Resources.Resources.MsgUnAuthorizeAccess,
                                                          UserResourcePermissions.Delete);
                    }
                }
            }
        }
    }
Beispiel #25
0
    private bool IsValidResourceId(Guid resourceId)
    {
        Resource resourceObj = null;

        using (ResourceDataAccess dataAccess = new ResourceDataAccess())
        {
            resourceObj = dataAccess.GetResource(resourceId);
        }

        return(resourceObj != null);
    }
Beispiel #26
0
    /// <summary>
    /// Delete the selected groups from DB.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Group_DeleteClicked(object sender, ZentityGridEventArgs e)
    {
        if (e.EntityIdList != null && e.EntityIdList.Count > 0)
        {
            using (ResourceDataAccess resourceDAL = new ResourceDataAccess(Utility.CreateContext()))
            {
                Utility.ShowMessage(GridErrorLabel, resourceDAL.DeleteGroups(e.EntityIdList, userToken), true);
            }

            FillGroupGrid();
        }
    }
Beispiel #27
0
        private void fileNameLink_Click(object sender, EventArgs e)
        {
            LinkButton lnkButton = sender as LinkButton;

            if (lnkButton != null)
            {
                using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext()))
                {
                    dataAccess.DownloadFile(new Guid(lnkButton.ID), this.Page.Response);
                }
            }
        }
Beispiel #28
0
    /// <summary>
    /// Initialized the user assignment user control.
    /// </summary>
    private void InitializeControls()
    {
        Group group = null;

        if (!Page.IsPostBack)
        {
            groupAssignment.ClearGroupList();
        }

        groupAssignment.ControlMode      = UserControls_GroupAssignment.RoleType.User;
        groupAssignment.UserSearchButton = Resources.Resources.ButtonSearchText;

        if (!string.IsNullOrEmpty(Id))
        {
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
            {
                group = (Group)dataAccess.GetResource(new Guid(Id));

                if (group == null)
                {
                    return;
                }
                group.Identities.Load();
                if (group.Identities != null)
                {
                    groupAssignment.SelectedIdentityList = group.Identities.ToList();
                }
            }
        }

        if (!string.IsNullOrEmpty(Id))
        {
            if (group.GroupName == UserManager.AllUsersGroupName)
            {
                groupInfoPanel.Enabled   = false;
                groupAssignment.IsEnable = false;
                groupAssignment.SelectedUserOrGroupType = UserControls_GroupAssignment.SelectedType.AllUsersGroupName;
            }
            else if (group.GroupName == UserManager.AdminGroupName)
            {
                groupInfoPanel.Enabled   = false;
                groupAssignment.IsEnable = true;
                groupAssignment.SelectedUserOrGroupType = UserControls_GroupAssignment.SelectedType.AdminGroupName;
            }
        }
        else
        {
            groupInfoPanel.Enabled   = true;
            groupAssignment.IsEnable = true;
        }

        Utility.ShowMessage(lblMessage, string.Empty, false);
    }
Beispiel #29
0
        /// <summary>
        /// Gets the subject entity.
        /// </summary>
        /// <returns> Subject entity. </returns>
        private object GetSubjectEntity()
        {
            Resource entity = null;

            using (ResourceDataAccess dataAccess = new ResourceDataAccess(base.CreateContext()))
            {
                entity = dataAccess.GetResource(SubjectItemId, Constants.ScholarlyWorkItemFullName);
                dataAccess.AuthorizeResource <Resource>(AuthenticatedToken, UserResourcePermissions.Update, entity, true);
            }

            return(entity);
        }
Beispiel #30
0
        /// <summary>
        /// Gets the data source.
        /// </summary>
        protected override void GetDataSource()
        {
            if (!this.Page.IsPostBack)
            {
                using (ResourceDataAccess resourceAccess = new ResourceDataAccess(base.CreateContext()))
                {
                    switch (BrowseBy)
                    {
                    case BrowseByCriteria.BrowseByYear:
                        if (!IsSecurityAwareControl)
                        {
                            this._yearRange = resourceAccess.GetYear(null);
                        }
                        else if (this.AuthenticatedToken != null)
                        {
                            this._yearRange = resourceAccess.GetYear(this.AuthenticatedToken);
                        }

                        break;

                    case BrowseByCriteria.BrowseByAuthors:
                        if (!IsSecurityAwareControl)
                        {
                            this._authorList = resourceAccess.GetAuthors(null).ToList();
                        }
                        else if (this.AuthenticatedToken != null)
                        {
                            this._authorList = resourceAccess.GetAuthors(this.AuthenticatedToken).ToList();
                        }
                        break;

                    case BrowseByCriteria.BrowseByResourceType:
                        this._resTypeList = resourceAccess.GetResourceTypes().ToList();
                        _resTypeList      = CoreHelper.FilterSecurityResourceTypes(_resTypeList).ToList();
                        break;

                    case BrowseByCriteria.BrowseByCategoryHierarchy:
                        PopulateRootNodeDropDown();
                        if (!string.IsNullOrEmpty(RootNodeDropDown.SelectedValue))
                        {
                            this._rootCategoryNode = resourceAccess.GetCategoryNodeWithHierarchy(
                                new Guid(RootNodeDropDown.SelectedValue));
                            if (IsSecurityAwareControl && _rootCategoryNode != null)
                            {
                                _authorizedCategoryNodeIds = GetAuthorizedCategoryNodes(AuthenticatedToken, _rootCategoryNode, resourceAccess);
                            }
                        }
                        break;
                    }
                }
            }
        }