Пример #1
0
    private void FillResourceGrid()
    {
        string searchText = txtSearchText.Text.Trim();

        int totalRecords   = 0;
        int fetchedRecords = _pageSize * ResourceTable.PageIndex;

        ResourceTable.PageSize = _pageSize;
        List <Resource> resourceList = new List <Resource>();

        using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
        {
            IEnumerable <Resource> resources = null;

            if (!rbSearchOptions.SelectedItem.Text.Equals(Resources.Resources.SearchInExistingList))
            {
                resources = dataAccess.GetResources(searchText);
            }
            else
            {
                resources = dataAccess.GetResourcesWithExplicitPermissions(Id, searchText, userToken);
            }
            resourceList = resources.OrderBy(tuple => tuple.Title).Skip(fetchedRecords).Take(_pageSize).ToList();
            totalRecords = resources.Count();

            Utility.UpdateResourcesEmptyTitle(resourceList);
        }

        if (!(totalRecords > 0))
        {
            lblErrorResourcePermission.Text      = Resources.Resources.NoRecordsFound;
            lblErrorResourcePermission.ForeColor = System.Drawing.Color.Red;
            lblErrorResourcePermission.Visible   = true;
        }

        if (resourceList != null)
        {
            //Update page count
            UpdatePageCount(ResourceTable, totalRecords);

            if (resourceList.Count > 0)
            {
                ResourceTable.DataSource = resourceList;
                ResourceTable.DataBind();
            }
        }
    }
Пример #2
0
    private ICollection <ScholarlyWork> FilterResourcesBasedOnPermissions(AuthenticatedToken token, string userPermission,
                                                                          ICollection <ScholarlyWork> resourceList)
    {
        List <ScholarlyWork> filteredResources = new List <ScholarlyWork>();

        if (token != null && resourceList != null && resourceList.Count > 0)
        {
            using (ResourceDataAccess dataAccess = new ResourceDataAccess())
            {
                if (UserResourcePermissions.Create.Equals(userPermission))
                {
                    if (dataAccess.HasCreatePermission(token))
                    {
                        foreach (ScholarlyWork scholWork in resourceList)
                        {
                            bool isAuthorized = true;
                            foreach (Contact contact in scholWork.Authors.Union(scholWork.Editors))
                            {
                                Contact cFound = dataAccess.GetResources <Contact>(ResourceStringComparison.Equals, contact.Title).FirstOrDefault();
                                if (cFound != null && !dataAccess.AuthorizeUser(token, userPermission, cFound.Id))
                                {
                                    isAuthorized = false;
                                    break;
                                }
                            }
                            if (isAuthorized)
                            {
                                filteredResources.Add(scholWork);
                            }
                        }
                    }
                }
                else
                {
                    foreach (ScholarlyWork scholWork in resourceList)
                    {
                        if (dataAccess.AuthorizeUser(token, userPermission, scholWork.Id))
                        {
                            filteredResources.Add(scholWork);
                        }
                    }
                }
            }
        }
        return(filteredResources);
    }
Пример #3
0
    protected void Step1NextButton_Click(object sender, EventArgs e)
    {
        if (this.fileUploadBibTeXFile.HasFile)
        {
            //this.LabelFileUploadMessage.Visible = false;
            using (Stream fileStream = this.fileUploadBibTeXFile.FileContent)
            {
                BibTeXConverter             bibConverter    = new BibTeXConverter(BibTeXParserBehavior.IgnoreParseErrors);
                ICollection <ScholarlyWork> importResources = (ICollection <ScholarlyWork>)bibConverter.Import(fileStream);

                if (importResources.Count == 0)
                {
                    this.PanelParsedEntries.Visible = false;
                    this.DisplayCannotImportMessage(Resources.Resources.BibtexImportNothingFound);
                    this.DisplayParsingErrors(bibConverter.ParserErrors, bibConverter.MappingErrors);
                }
                else
                {
                    ICollection <ScholarlyWork> scholarlyWorksExistsAndCited    = new List <ScholarlyWork>();
                    ICollection <ScholarlyWork> scholarlyWorksExistsButNotCited = new List <ScholarlyWork>();
                    ICollection <Guid>          resourceExistsButNotCitedId     = new List <Guid>();
                    ICollection <ScholarlyWork> newResources = new List <ScholarlyWork>();
                    IQueryable <ScholarlyWork>  citationsOfAScholarlyWork = null;

                    this.PanelParsedEntries.Visible = true;


                    // Create collection because of Linq query operate on "context.Resources" does not accept
                    // equals method in the predicate
                    // Get cites resource of selected resource

                    if (_scholarlyWorkObj != null)
                    {
                        citationsOfAScholarlyWork = _scholarlyWorkObj.Cites.AsQueryable <ScholarlyWork>();
                    }
                    else
                    {
                        this.DisplayError(Resources.Resources.ResourceNotFound);
                        return;
                    }

                    List <ScholarlyWork> actualResourceMatchCriteria = new List <ScholarlyWork>();
                    foreach (ScholarlyWork resource in importResources)
                    {
                        actualResourceMatchCriteria.Clear();
                        using (ResourceDataAccess resourceDAL = new ResourceDataAccess())
                        {
                            var resourcesInZentityContext = resourceDAL.GetResources <ScholarlyWork>
                                                                (Zentity.Web.UI.ResourceStringComparison.Equals, resource.Title);

                            foreach (ScholarlyWork tempResourcInZentityContext in resourcesInZentityContext)
                            {
                                if (tempResourcInZentityContext.GetType().Equals(resource.GetType()))
                                {
                                    actualResourceMatchCriteria.Add(tempResourcInZentityContext);
                                    break;
                                }
                            }
                        }

                        if (actualResourceMatchCriteria.Count > 0)
                        {
                            var resourceInCites = citationsOfAScholarlyWork.Where(
                                citeResource => citeResource.Id.Equals
                                    (actualResourceMatchCriteria.First <ScholarlyWork>().Id));
                            if (resourceInCites.Count() > 0)
                            {
                                // current resource's title and type matches with cited resource of selected resource
                                scholarlyWorksExistsAndCited.Add(actualResourceMatchCriteria.First());
                            }
                            else
                            {
                                // current resource's title and type matches with resource in the repository but not in cited
                                scholarlyWorksExistsButNotCited.Add(actualResourceMatchCriteria.First());
                                resourceExistsButNotCitedId.Add(actualResourceMatchCriteria.First().Id);
                            }
                        }
                        else
                        {
                            // Current resource is not exist in the repository
                            newResources.Add(resource);
                        }
                    }
                    AuthenticatedToken          token = Session[Constants.AuthenticationTokenKey] as AuthenticatedToken;
                    ICollection <ScholarlyWork> filteredResourceToBeCited = FilterResourcesBasedOnPermissions(token,
                                                                                                              Constants.PermissionRequiredForAssociation, scholarlyWorksExistsButNotCited);
                    ICollection <ScholarlyWork> resourceNotToBeCited         = scholarlyWorksExistsButNotCited.Except(filteredResourceToBeCited).ToList();
                    ICollection <ScholarlyWork> filteredResourceToBeImported = FilterResourcesBasedOnPermissions(token,
                                                                                                                 UserResourcePermissions.Create, newResources);
                    ICollection <ScholarlyWork> resourceNotToBeImported = newResources.Except(filteredResourceToBeImported).ToList();

                    Session.Add(_bibtexImportResource, filteredResourceToBeImported);
                    Session.Add(_bibtexResourceToBeCitedId, filteredResourceToBeCited.Select(tuple => tuple.Id).ToList());
                    ResourcesCitedDataSource           = scholarlyWorksExistsAndCited;
                    ResourcesToBeCitedDataSource       = filteredResourceToBeCited;
                    ResourcesNotToBeCitedDataSource    = resourceNotToBeCited;
                    ResourcesNotToBeImportedDataSource = resourceNotToBeImported;

                    RefreshResults(ResourcesCited, scholarlyWorksExistsAndCited);
                    RefreshResults(ResourcesToBeCited, filteredResourceToBeCited);
                    RefreshResults(ResourcesToBeImported, filteredResourceToBeImported);

                    if (resourceNotToBeCited.Count > 0)
                    {
                        RefreshResults(ResourcesNotToBeCited, resourceNotToBeCited);
                    }
                    else
                    {
                        ResourcesNotToBeCitedLabel.Visible = false;
                    }

                    if (resourceNotToBeImported.Count > 0)
                    {
                        RefreshResults(ResourcesNotToBeImported, resourceNotToBeImported);
                    }
                    else
                    {
                        ResourcesNotToBeImportedLabel.Visible = false;
                    }

                    this.DisplayParsingErrors(bibConverter.ParserErrors, bibConverter.MappingErrors);
                }
            }
            Wizard1.ActiveStepIndex = 1;
        }
    }