Exemple #1
0
        public PagedResultList <SnapshotAggregatedInfoContract> GetPublishedSnapshotWithAggregatedInfo(long projectId, int?start, int?count, string filterByComment)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var publishedSnapshots = m_snapshotRepository.InvokeUnitOfWork(x => x.GetPublishedSnapshots(projectId, startValue, countValue, filterByComment));
            var snapshotInfo       = m_snapshotRepository.InvokeUnitOfWork(x => x.GetSnapshotsResourcesCount(publishedSnapshots.List.Select(s => s.Id).ToArray()));

            var snapshotContracts = m_mapper.Map <List <SnapshotAggregatedInfoContract> >(publishedSnapshots.List);

            foreach (var snapshotContract in snapshotContracts)
            {
                var dbSnapshot = publishedSnapshots.List.FirstOrDefault(x => x.Id == snapshotContract.Id);
                if (dbSnapshot != null)
                {
                    snapshotContract.Author        = m_userDetailManager.GetUserFullName(dbSnapshot.CreatedByUser);
                    snapshotContract.ResourcesInfo = new List <SnapshotResourcesInfoContract>();

                    foreach (var aggregatedInfo in snapshotInfo.Where(x => x.Id == snapshotContract.Id))
                    {
                        snapshotContract.ResourcesInfo.Add(new SnapshotResourcesInfoContract
                        {
                            ResourceType   = m_mapper.Map <ResourceTypeEnumContract>(aggregatedInfo.Type),
                            PublishedCount = aggregatedInfo.ResourcesCount
                        });
                    }
                }
            }

            return(new PagedResultList <SnapshotAggregatedInfoContract>
            {
                List = snapshotContracts,
                TotalCount = publishedSnapshots.Count
            });
        }
        public IList <ResourceWithLatestVersionContract> GetResourceList(long projectId, ResourceTypeEnumContract?resourceTypeContract)
        {
            ResourceTypeEnum?resourceType = null;

            if (resourceTypeContract.HasValue)
            {
                resourceType = m_mapper.Map <ResourceTypeEnum>(resourceTypeContract);
            }
            var dbResult = m_resourceRepository.InvokeUnitOfWork(x => x.GetProjectLatestResources(projectId, resourceType));

            var resultList = new List <ResourceWithLatestVersionContract>();
            var userCache  = new Dictionary <int, string>();

            foreach (var resource in dbResult)
            {
                var latestResourceVersion = resource.LatestVersion;
                var resourceContract      = m_mapper.Map <ResourceWithLatestVersionContract>(resource);
                var userId = latestResourceVersion.CreatedByUser.Id;
                if (!userCache.TryGetValue(userId, out var userName))
                {
                    userCache.Add(userId, m_userDetailManager.GetUserFullName(latestResourceVersion.CreatedByUser));
                    userCache.TryGetValue(userId, out userName);
                }

                resourceContract.LatestVersion.Author          = userName;
                resourceContract.LatestVersion.RelatedResource = GetRelatedResourceContract(latestResourceVersion);
                resultList.Add(resourceContract);
            }

            return(resultList);
        }
Exemple #3
0
        public IList <ResourceVersionContract> GetResourceVersionHistory(long resourceId, int?higherVersion, int lowerVersion)
        {
            var dbResult = m_resourceRepository.InvokeUnitOfWork(x => x.GetResourceVersionHistory(resourceId, higherVersion, lowerVersion));

            var resultList = new List <ResourceVersionContract>();
            var userCache  = new Dictionary <int, string>();

            foreach (var resource in dbResult)
            {
                var resourceContract = m_mapper.Map <ResourceVersionContract>(resource);
                var userId           = resource.CreatedByUser.Id;
                if (!userCache.TryGetValue(userId, out var userName))
                {
                    userCache.Add(userId, m_userDetailManager.GetUserFullName(resource.CreatedByUser));
                    userCache.TryGetValue(userId, out userName);
                }

                resourceContract.Author = userName;
                resultList.Add(resourceContract);
            }

            return(resultList);
        }