public async Task <IActionResult> AddAssets([FromBody] AddAssetRequest request) { var createServiceCommand = new CreateAssetCommand(request); var result = await mediator.Send(createServiceCommand); return(StatusCode((int)result.Code, result.Value)); }
/// ----------------------------------------------------------------- /// <summary> /// </summary> // ----------------------------------------------------------------- public ResponseBase AddAssetHandler(RequestBase irequest) { if (m_cache == null) { return(OperationFailed("No asset cache")); } if (irequest.GetType() != typeof(AddAssetRequest)) { return(OperationFailed("wrong type")); } AddAssetRequest request = (AddAssetRequest)irequest; UUID id = request.Asset.AssetID; if ((id == UUID.Zero) || (m_cache.Get(id.ToString()) == null)) { if (id == UUID.Zero) { id = UUID.Random(); } AssetBase asset = (AssetBase)request; asset.Local = true; asset.Temporary = false; m_cache.Cache(asset); } return(new AddAssetResponse(id)); }
public async Task <ActionResult <Asset> > AddAsset() { var assetClient = _mindSphereSdkService.GetAssetManagementClient(); var request = new AddAssetRequest() { Body = new AssetAdd() { Name = "MyNewAsset", TypeId = "iiotdgli.mobilephone", ParentId = "ec206f76b04a49a4938c1573b35b6688", } }; return(StatusCode(200, await assetClient.AddAssetAsync(request))); }
/// <summary> /// Adds the assets. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public async Task <APIResponse> AddAssets(AddAssetRequest request) { try { var client = httpClientFactory.CreateClient(VendorServiceOperation.serviceName); var param = JsonConvert.SerializeObject(request); HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json"); var response = await client.PostAsync(servicesConfig.Vendor + VendorServiceOperation.AddAssets(), contentPost); return(JsonConvert.DeserializeObject <APIResponse>(await response.Content.ReadAsStringAsync())); } catch (Exception ex) { logger.Error(ex, "Exception in method 'AddAssets()'"); var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message; return(new APIResponse(exMessage, HttpStatusCode.InternalServerError)); } }
/// <summary> /// Initializes a new instance of the <see cref="CreateAssetCommand"/> class. /// </summary> /// <param name="request">The request.</param> public CreateAssetCommand(AddAssetRequest request) { Request = request; }
public async Task <IActionResult> AddAssets([FromBody] AddAssetRequest request) { var result = await assetService.AddAssets(request); return(StatusCode((int)result.Code, result.Value)); }