public ActionResult DeleteAsset(Guid?AssetUID, DateTime?ActionUTC) { if (AssetUID == Guid.Empty || AssetUID == null || !Guid.TryParse(AssetUID.ToString(), out Guid g)) { return(BadRequest("AssetUID field values must be valid")); } try { var assetDetails = _assetService.GetAsset(AssetUID.Value); if (assetDetails == null || assetDetails.StatusInd == 0) { return(BadRequest("Asset does not exist")); } var asset = new DeleteAssetPayload { AssetUID = AssetUID.Value, ActionUTC = DateTime.UtcNow, ReceivedUTC = DateTime.UtcNow }; if (_assetService.DeleteAsset(asset)) { return(Ok(asset.AssetUID.ToString())); } return(BadRequest("Unable to save to db. Make sure request is not duplicated and all keys exist")); } catch (Exception ex) { _logger.LogError(" Delete Asset Exception: " + ex.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public virtual bool DeleteAsset(DeleteAssetPayload asset) { string guid = asset.AssetUID.Value.ToStringWithoutHyphens(); DateTime actionUTC = DateTime.UtcNow; string query = $"update md_asset_Asset set StatusInd = 0, UpdateUTC = '{actionUTC.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}' where AssetUID = {guid.WrapWithUnhex()}"; //Kafka message asset.ActionUTC = actionUTC; var message = new KafkaMessage { Key = asset.AssetUID.ToString(), Message = new { DeleteAssetEvent = asset } }; var actions = new List <Action>() { () => _transaction.Delete(query), () => assetTopicNames?.ForEach((topic) => { message.Topic = topic; _transaction.Publish(message); }) }; return(_transaction.Execute(actions)); }
public void Delete_Asset() { //Arrange for Create var assetObject = new DeleteAssetPayload() { AssetUID = Guid.NewGuid(), ActionUTC = DateTime.UtcNow, ReceivedUTC = DateTime.UtcNow, }; _transaction.Execute(Arg.Any <List <Action> >()).Returns(x => { foreach (var action in x.Arg <List <Action> >()) { action(); } return(true); }); //Act Assert.True(_assetServices.DeleteAsset(assetObject)); }