Ejemplo n.º 1
0
        public async Task <AddArtifactsToCollectionResult> AddArtifactsToCollectionAsync(
            int collectionId, IEnumerable <int> artifactIds, int userId)
        {
            if (collectionId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(collectionId));
            }

            if (userId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            AddArtifactsToCollectionResult result = null;

            Func <IDbTransaction, long, Task> action = async(transaction, transactionId) =>
            {
                var collection = await ValidateCollectionAsync(collectionId, userId, transaction);

                var artifactIdsToAdd    = artifactIds.ToList();
                var accessibleArtifacts = await GetAccessibleArtifactsAsync(artifactIdsToAdd, userId, transaction);

                var validArtifacts   = accessibleArtifacts.Where(i => CanAddArtifactToCollection(i, collection)).ToList();
                var validArtifactIds = validArtifacts.Select(a => a.HolderId);

                var addedCount = await _collectionsRepository.AddArtifactsToCollectionAsync(
                    collection.Id, validArtifactIds, userId, transaction);

                result = new AddArtifactsToCollectionResult
                {
                    AddedCount = addedCount,
                    Total      = artifactIdsToAdd.Count
                };
            };

            await _sqlHelper.RunInTransactionAsync(ServiceConstants.RaptorMain, action);

            return(result);
        }
Ejemplo n.º 2
0
        public void Initialize()
        {
            _userId  = 1;
            _session = new Session {
                UserId = _userId
            };
            _pagination = new Pagination {
                Limit = int.MaxValue, Offset = 0
            };

            _collectionsServiceMock  = new Mock <ICollectionsService>();
            _artifactListServiceMock = new Mock <IArtifactListService>();

            _collectionsController = new CollectionsController(
                _collectionsServiceMock.Object,
                _artifactListServiceMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            _collectionsController.Request.Properties[ServiceConstants.SessionProperty] = _session;

            _artifactIds = new HashSet <int> {
                1, 2, 3
            };

            _collectionId       = 1;
            _addArtifactsResult = new AddArtifactsToCollectionResult
            {
                AddedCount = 1,
                Total      = 1
            };

            _removeArtifactsFromCollectionResult = new RemoveArtifactsFromCollectionResult
            {
                RemovedCount = 1,
                Total        = 3
            };

            _profileColumnsDto = new ProfileColumnsDto
            {
                Items = new List <ProfileColumn>
                {
                    new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Text, 2)
                }
            };

            _expectedCollectionArtifacts = new CollectionArtifacts
            {
                ItemsCount           = 2,
                ArtifactListSettings = new ArtifactListSettings
                {
                    Columns = new List <ProfileColumn>
                    {
                        new ProfileColumn
                        {
                            Predefined     = PropertyTypePredefined.Name,
                            PrimitiveType  = PropertyPrimitiveType.Text,
                            PropertyName   = "Name",
                            PropertyTypeId = 80
                        },
                        new ProfileColumn
                        {
                            Predefined     = PropertyTypePredefined.Description,
                            PrimitiveType  = PropertyPrimitiveType.Text,
                            PropertyName   = "Description",
                            PropertyTypeId = 81
                        }
                    },
                    Filters = new List <ArtifactListFilter>()
                },
                Items = new List <ArtifactDto>
                {
                    new ArtifactDto
                    {
                        ArtifactId     = 7545,
                        ItemTypeId     = 134,
                        PredefinedType = 4107,
                        PropertyInfos  = new List <PropertyValueInfo>
                        {
                            new PropertyValueInfo
                            {
                                PropertyTypeId = 80,
                                Value          = "Value_Name"
                            },
                            new PropertyValueInfo
                            {
                                PropertyTypeId = 81,
                                Value          = "Value_Description",
                                IsRichText     = true
                            }
                        }
                    },
                    new ArtifactDto
                    {
                        ArtifactId     = 7551,
                        ItemTypeId     = 132,
                        PredefinedType = 4105,
                        PropertyInfos  = new List <PropertyValueInfo>
                        {
                            new PropertyValueInfo
                            {
                                PropertyTypeId = 80,
                                Value          = "Value_Name_2"
                            },
                            new PropertyValueInfo
                            {
                                PropertyTypeId = 81,
                                Value          = "Value_Description_2",
                                IsRichText     = true
                            }
                        }
                    }
                }
            };

            _columns = new GetColumnsDto
            {
                SelectedColumns = new List <ProfileColumn>
                {
                    new ProfileColumn("Custom", PropertyTypePredefined.Name, PropertyPrimitiveType.Number, 3)
                },
                UnselectedColumns = new List <ProfileColumn>
                {
                    new ProfileColumn("Custom", PropertyTypePredefined.Name, PropertyPrimitiveType.Number, 3)
                }
            };
        }