public async Task <IActionResult> Post([FromQuery] DecommissionedAssetQuery query) { var assetDto = await _assetService.GetAssetForDecommissioning(query.Id); if (assetDto != null && query.ChangePlanId == null) { var decommissionedAsset = CreateDecommissionedAsset(assetDto, query); //check to see if it's a blade chassis, if yes, decommission + delete all the blades within it too //decommissionedAsset already has the information of all the blades in it already await DecommissionBladeChassis(assetDto, query); //deleting asset from active asset column + adding the decommissioned asset to the table await _assetService.DeleteAssetAsync(query.Id); await _assetService.CreateDecommissionedAssetAsync(decommissionedAsset); } if (query.ChangePlanId != null && query.ChangePlanId != Guid.Empty) { var updatedAssetChangePlan = await _changePlanService.GetChangePlanItemAsync(query.ChangePlanId ?? Guid.Empty, query.Id); //checking to see if this asset has been created/updated in the change plan //using this info to create and display the new decommissioned asset var decommissionedAsset = new DecommissionedAssetDto(); if (updatedAssetChangePlan != null) { var newAssetDto = new AssetDto(); if (updatedAssetChangePlan.ExecutionType.Equals("create")) { var updatedAssetApi = JsonConvert.DeserializeObject <CreateAssetApiDto>(updatedAssetChangePlan.NewData); newAssetDto = _mapper.Map <AssetDto>(updatedAssetApi); } else if (updatedAssetChangePlan != null && updatedAssetChangePlan.ExecutionType.Equals("update")) { var updatedAssetApi = JsonConvert.DeserializeObject <UpdateAssetApiDto>(updatedAssetChangePlan.NewData); newAssetDto = _mapper.Map <AssetDto>(updatedAssetApi); } var updateadAssetDto = await _changePlanService.FillFieldsInAssetApiForChangePlans(newAssetDto); if (updateadAssetDto.Model.MountType.Equals("chassis")) { await DecommissionBladeChangePlan(updateadAssetDto, query); } decommissionedAsset = CreateDecommissionedAsset(updateadAssetDto, query); } //this asset to be decommissioned was not found in the change assets items and //it has been found in the assets data else if (assetDto != null) { if (assetDto.Model.MountType.Equals("chassis")) { await DecommissionBladeChangePlan(assetDto, query); } decommissionedAsset = CreateDecommissionedAsset(assetDto, query); } await _changePlanService.CreateChangePlanItemAsync(query.ChangePlanId ?? Guid.Empty, query.Id, decommissionedAsset); } return(Ok()); }
public async Task <Guid> CreateDecommissionedAssetAsync(DecommissionedAssetDto asset) { var entity = _mapper.Map <DecommissionedAsset>(asset); await _repository.AddDecomissionedAssetAsync(entity); //await _auditEventLogger.LogEventAsync(new AssetCreatedEvent(asset)); return(entity.Id); }
public async Task <Guid> CreateChangePlanItemAsync(Guid changePlanId, Guid assetId, DecommissionedAssetDto decommissionedAsset) { var changePlanItemDto = new ChangePlanItemDto { ChangePlanId = changePlanId, ExecutionType = "decommission", AssetId = assetId, NewData = JsonConvert.SerializeObject(decommissionedAsset), PreviousData = decommissionedAsset.Data, CreatedDate = DateTime.Now }; var entity = _mapper.Map <ChangePlanItem>(changePlanItemDto); await _repository.AddChangePlanItemAsync(entity); return(entity.Id); }