예제 #1
0
    public async void CreateStronglyTypedAsset()
    {
        // Remove next line in codesample
        var client = _fileSystemFixture.CreateMockClientWithResponse("FileReferenceResponse.json");

        var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello world from CM API .NET SDK"));
        var fileName = "Hello.txt";
        var contentType = "text/plain";

        // Returns a reference that you can later use to create an asset
        var fileResult = await client.UploadFileAsync(new FileContentSource(stream, fileName, contentType));

        // Defines the content elements to create
        var stronglyTypedTaxonomyElements = new AssetMetadataModel
        {
            TaxonomyCategories = new TaxonomyElement()
            {
                Value = new[] { "hello", "SDK" }.Select(Reference.ByCodename)
            },
        };

        // Defines the asset to create
        var asset = new AssetCreateModel<AssetMetadataModel>
        {
            FileReference = fileResult,
            Elements = stronglyTypedTaxonomyElements
        };

        // Remove next line in codesample
        client = _fileSystemFixture.CreateMockClientWithResponse("AssetResponse.json");
        // Creates an asset
        var response = await client.CreateAssetAsync(asset);
    }
예제 #2
0
    public async Task CreateAssetAsync_DynamicallyTyped_WithFileContent_FileContentIsNull_Throws()
    {
        var client = _fileSystemFixture.CreateMockClientWithoutResponse();

        var updateModel = new AssetCreateModel {
            Title = "xxx"
        };

        await client.Invoking(c => c.CreateAssetAsync(null, updateModel))
        .Should().ThrowExactlyAsync <ArgumentNullException>();
    }
예제 #3
0
    /// <inheritdoc />
    public async Task <AssetModel <T> > CreateAssetAsync <T>(AssetCreateModel <T> asset) where T : new()
    {
        if (asset == null)
        {
            throw new ArgumentNullException(nameof(asset));
        }

        var result = await CreateAssetAsync(_modelProvider.GetAssetCreateModel(asset));

        return(_modelProvider.GetAssetModel <T>(result));
    }
예제 #4
0
        public async Task <AssetViewModel> AddAssetAsync(Guid userId, AssetCreateModel createModel)
        {
            Money money = new Money(createModel.Value, createModel.Currency);
            Asset asset = await _assetRepository.CreateAsync(userId, createModel.Name, money, createModel.IsActive, DateTime.UtcNow);

            await _unitOfWork.SaveChangesAsync();

            AssetViewModel result = new AssetViewModel(asset);

            return(result);
        }
예제 #5
0
    /// <inheritdoc />
    public async Task <AssetModel> CreateAssetAsync(AssetCreateModel asset)
    {
        if (asset == null)
        {
            throw new ArgumentNullException(nameof(asset));
        }

        var endpointUrl = _urlBuilder.BuildAssetsUrl();
        var response    = await _actionInvoker.InvokeMethodAsync <AssetCreateModel, AssetModel>(endpointUrl, HttpMethod.Post, asset);

        return(response);
    }
예제 #6
0
        public async Task <ActionResult <AssetViewModel> > AddAsset([FromBody] AssetCreateModel createModel)
        {
            UserViewModel user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(HandleUserNotFoundResult());
            }

            AssetViewModel result = await _assetService.AddAssetAsync(user.Id, createModel);

            return(HandleResult(result));
        }
예제 #7
0
    public async Task CreateAssetAsync_DynamicallyTyped_CreatesAsset()
    {
        var client = _fileSystemFixture.CreateMockClientWithResponse("Asset.json");

        var expected = GetExpectedDynamicAssetModel();

        var createModel = new AssetCreateModel
        {
            Title      = expected.Title,
            ExternalId = expected.ExternalId,
            Elements   = expected.Elements
        };

        var response = await client.CreateAssetAsync(createModel);

        response.Should().BeEquivalentTo(expected);
    }
예제 #8
0
        public IActionResult AddAsset(AssetCreateModel newAsset)
        {
            var statuses = _assets.GetStatuses();

            Book asset = new Book();

            asset.Title          = newAsset.Title;
            asset.Status         = _assets.GetStatuses().FirstOrDefault(s => s.Id == 6);
            asset.NumberOfCopies = newAsset.NumberOfCopies;
            asset.Location       = _assets.GetBranches().FirstOrDefault(b => b.Id == newAsset.CurrentLocationId);
            asset.Year           = newAsset.Year;
            asset.Author         = newAsset.AuthorOrDirector;
            asset.Cost           = newAsset.Cost;
            asset.ISBN           = newAsset.ISBN;
            asset.DeweyIndex     = newAsset.DeweyCallNumber;
            asset.ImageUrl       = newAsset.ImageUrl;

            _assets.AddBook(asset);

            return(View("./SuccessAdd"));
        }
예제 #9
0
    public async Task CreateAssetAsync_DynamicallyTyped_WithFileContent_CreatesAsset()
    {
        var client = _fileSystemFixture.CreateMockClientWithResponse("File.json", "Asset.json");

        var expected = GetExpectedDynamicAssetModel();

        var stream      = new MemoryStream(Encoding.UTF8.GetBytes("Hello world from CM API .NET SDK"));
        var fileName    = "Hello.txt";
        var contentType = "text/plain";

        var updateModel = new AssetCreateModel
        {
            Title    = expected.Title,
            Elements = expected.Elements
        };

        var content = new FileContentSource(stream, fileName, contentType);

        var response = await client.CreateAssetAsync(content, updateModel);

        response.Should().BeEquivalentTo(expected);
    }
예제 #10
0
    /// <summary>
    /// Creates asset.
    /// </summary>
    /// <param name="client"></param>
    /// <param name="fileContent">Represents the content of the file.</param>
    /// <param name="assetCreateModel">Updated values for the strongly typed asset.</param>
    public async static Task <AssetModel <T> > CreateAssetAsync <T>(this IManagementClient client, FileContentSource fileContent, AssetCreateModel <T> assetCreateModel) where T : new()
    {
        if (fileContent == null)
        {
            throw new ArgumentNullException(nameof(fileContent));
        }
        if (assetCreateModel == null)
        {
            throw new ArgumentNullException(nameof(assetCreateModel));
        }

        var fileResult = await client.UploadFileAsync(fileContent);

        assetCreateModel.FileReference = fileResult;

        var response = await client.CreateAssetAsync(assetCreateModel);

        return(response);
    }
예제 #11
0
 public void GivenAssetCreateModel(string assetName, string currencyName, bool isActive)
 {
     _assetCreateModel = new AssetCreateModel(assetName, currencyName, isActive, 1.0M);
 }