Beispiel #1
0
 private static void UpdateAssetTitle(AssetUpdateModel updatedAsset, AssetUpsertModel asset)
 {
     if (updatedAsset.Title != null)
     {
         asset.Title = updatedAsset.Title;
     }
 }
Beispiel #2
0
        public bool UpdateAsset(AssetUpdateModel assetUpdateModel)
        {
            var newerAsset = new Asset
            {
                AssetId    = assetUpdateModel.AssetId,
                Properties = (PropertyEnum)EnumExtensions.GetEnumFromDisplayValue <PropertyEnum>(assetUpdateModel.Properties),
                Timestamp  = assetUpdateModel.Timestamp,
                Value      = assetUpdateModel.Value
            };

            var updatedAsset = GetAsset(newerAsset);

            if (updatedAsset == null)
            {
                Console.WriteLine($"Asset with the 'AssetId: {newerAsset.AssetId}, Properties: {newerAsset.Properties}' could not be found in Db.");

                return(false);
            }

            var isSuitable = CheckAssetCanBeAdded(newerAsset);

            if (isSuitable)
            {
                updatedAsset.Properties = newerAsset.Properties;
                updatedAsset.Value      = newerAsset.Value;
                updatedAsset.Timestamp  = newerAsset.Timestamp;

                _context.SaveChanges();

                return(true);
            }

            Console.WriteLine("Asset cannot be updated because of its Timestamp value.");
            return(false);
        }
Beispiel #3
0
        public async Task <AssetViewModel> UpdateAsync(Guid userId, Guid id, AssetUpdateModel model)
        {
            Asset asset = await _assetRepository.GetByIdAsync(userId, id);

            if (asset == null)
            {
                throw new Exception($"Asset {id} not found!");
            }

            bool balanceExists = await _balanceRepository.ExistsAssetBalanceAsync(userId, id);

            if (balanceExists && !asset.Balance.Currency.Equals(model.Currency, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception($"Can't update currency of the Asset {id} if Asset's Balance exists!");
            }

            Money money  = new Money(model.Value, model.Currency);
            Asset result = await _assetRepository.UpdateAsync(userId, id, model.Name, money, model.IsActive, DateTime.UtcNow);

            await _unitOfWork.SaveChangesAsync();

            AssetViewModel viewModel = new AssetViewModel(result);

            return(viewModel);
        }
Beispiel #4
0
        public async Task <ActionResult <AssetViewModel> > UpdateAsset(Guid id, [FromBody] AssetUpdateModel updateModel)
        {
            UserViewModel user = await GetCurrentUserAsync();

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

            AssetViewModel result = await _assetService.UpdateAsync(user.Id, id, updateModel);

            return(HandleResult(result));
        }
Beispiel #5
0
        public async Task <IActionResult> PutAsset(Guid id, AssetUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = new UpdateAssetCommand
            {
                Id    = id,
                Input = model
            };

            return(await ExecuteRequest(command).ConfigureAwait(false));
        }
        /// <summary>
        /// Updates given asset.
        /// </summary>
        /// <param name="identifier">The identifier of the asset.</param>
        /// <param name="asset">Represents updated asset.</param>
        /// <returns>The <see cref="AssetModel"/> instance that represents updated asset.</returns>
        public async Task <AssetModel> UpdateAssetAsync(AssetIdentifier identifier, AssetUpdateModel asset)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }

            var endpointUrl = _urlBuilderV2.BuildAssetsUrl(identifier);
            var response    = await _actionInvoker.InvokeMethodAsync <AssetUpdateModel, AssetModel>(endpointUrl, HttpMethod.Put, asset);

            return(response);
        }
Beispiel #7
0
        /// <summary>
        /// Creates or updates the given asset.
        /// </summary>
        /// <param name="client">Content management client instance.</param>
        /// <param name="externalId">The external identifier of the asset.</param>
        /// <param name="fileContent">Represents the content of the file.</param>
        /// <param name="updatedAsset">Updated values for asset.</param>
        /// <returns>The <see cref="AssetModel"/> instance that represents created or updated asset.</returns>
        public static async Task <AssetModel> UpsertAssetByExternalIdAsync(this ContentManagementClient client, string externalId, FileContentSource fileContent, AssetUpdateModel updatedAsset)
        {
            if (string.IsNullOrEmpty(externalId))
            {
                throw new ArgumentException("The external id is not specified.", nameof(externalId));
            }

            if (fileContent == null)
            {
                throw new ArgumentNullException(nameof(fileContent));
            }

            if (updatedAsset == null)
            {
                throw new ArgumentNullException(nameof(updatedAsset));
            }

            if (updatedAsset.Descriptions == null)
            {
                throw new ArgumentNullException(nameof(updatedAsset.Descriptions));
            }

            var fileResult = await client.UploadFileAsync(fileContent);

            var asset = new AssetUpsertModel
            {
                FileReference = fileResult,
                Descriptions  = updatedAsset.Descriptions
            };

            UpdateAssetTitle(updatedAsset, asset);

            var response = await client.UpsertAssetByExternalIdAsync(externalId, asset);

            return(response);
        }
Beispiel #8
0
        /// <summary>
        /// Creates asset.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="fileContent">Represents the content of the file.</param>
        /// <param name="assetUpdateModel">Updated values for asset.</param>
        public static async Task <AssetModel> CreateAssetAsync(this ContentManagementClient client, FileContentSource fileContent, AssetUpdateModel assetUpdateModel)
        {
            if (fileContent == null)
            {
                throw new ArgumentNullException(nameof(fileContent));
            }
            if (assetUpdateModel == null)
            {
                throw new ArgumentNullException(nameof(assetUpdateModel));
            }

            if (assetUpdateModel.Descriptions == null)
            {
                throw new ArgumentNullException(nameof(assetUpdateModel.Descriptions));
            }

            var fileResult = await client.UploadFileAsync(fileContent);

            var asset = new AssetUpsertModel
            {
                FileReference = fileResult,
                Descriptions  = assetUpdateModel.Descriptions,
                Title         = assetUpdateModel.Title
            };

            var response = await client.CreateAssetAsync(asset);

            return(response);
        }
Beispiel #9
0
 public void GivenSetAssetName(string assetName, string currencyName, bool isActive)
 {
     _updateModel = new AssetUpdateModel(assetName, currencyName, isActive, 1.0M);
 }
Beispiel #10
0
 public bool UpdateAsset([FromBody] AssetUpdateModel assetUpdateModel)
 {
     return(_assetService.UpdateAsset(assetUpdateModel));
 }