Beispiel #1
0
        public ProjectListData GetProjectList(int start, int count)
        {
            var work           = new GetProjectListWork(m_projectRepository, start, count);
            var resultEntities = work.Execute();

            var result = new ProjectListData
            {
                List       = Mapper.Map <List <ProjectContract> >(resultEntities),
                TotalCount = work.GetResultCount()
            };

            return(result);
        }
Beispiel #2
0
        public PagedResultList <ProjectDetailContract> GetProjectList(int?start, int?count, ProjectTypeContract?projectType,
                                                                      ProjectOwnerTypeContract projectOwnerType, string filterByName, bool fetchPageCount, bool fetchAuthors,
                                                                      bool fetchResponsiblePersons, bool fetchLatestChangedResource, bool fetchPermissions)
        {
            var startValue      = PagingHelper.GetStart(start);
            var countValue      = PagingHelper.GetCountForProject(count);
            var projectTypeEnum = m_mapper.Map <ProjectTypeEnum?>(projectType);

            var userId = m_authenticationManager.GetCurrentUserId();

            var work = new GetProjectListWork(m_projectRepository, m_metadataRepository, startValue, countValue, projectTypeEnum,
                                              projectOwnerType, userId, filterByName, fetchPageCount, fetchAuthors, fetchResponsiblePersons, fetchLatestChangedResource, fetchPermissions);
            var resultEntities = work.Execute();

            var metadataList       = work.GetMetadataResources();
            var pageCountList      = work.GetPageCountList();
            var latestChangesList  = work.GetLatestChangedResources();
            var userPermissionDict = work.GetUserPermission();
            var resultList         = m_mapper.Map <List <ProjectDetailContract> >(resultEntities);

            foreach (var projectContract in resultList)
            {
                var metadataResource   = metadataList.FirstOrDefault(x => x.Resource.Project.Id == projectContract.Id);
                var pageCountResult    = pageCountList.FirstOrDefault(x => x.ProjectId == projectContract.Id);
                var latestChangeResult = latestChangesList.FirstOrDefault(x => x.ProjectId == projectContract.Id);

                var metadataContract = m_mapper.Map <ProjectMetadataContract>(metadataResource);
                projectContract.LatestMetadata = metadataContract;
                projectContract.PageCount      = pageCountResult?.PageCount;
                projectContract.CreatedByUser  = m_userDetailManager.GetUserContractForUser(projectContract.CreatedByUser);

                if (fetchAuthors && metadataResource != null)
                {
                    projectContract.Authors = m_mapper.Map <List <OriginalAuthorContract> >(metadataResource.Resource.Project.Authors);
                }

                if (fetchResponsiblePersons && metadataResource != null)
                {
                    projectContract.ResponsiblePersons =
                        m_mapper.Map <List <ProjectResponsiblePersonContract> >(metadataResource.Resource.Project.ResponsiblePersons);
                }

                if (fetchLatestChangedResource && latestChangeResult != null)
                {
                    projectContract.LatestChangeTime = latestChangeResult.CreateTime;
                    projectContract.EditedByUser     = m_userDetailManager.GetUserContract(latestChangeResult.CreatedByUserId);
                }

                if (fetchPermissions)
                {
                    userPermissionDict.TryGetValue(projectContract.Id, out var permissions);
                    projectContract.CurrentUserPermissions = m_projectPermissionConverter.GetAggregatedPermissions(permissions);
                }
            }

            return(new PagedResultList <ProjectDetailContract>
            {
                List = resultList,
                TotalCount = work.GetResultCount()
            });
        }