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());
        }
        //TODO: May want to put this somewhere else
        private DecommissionedAssetDto CreateDecommissionedAsset(AssetDto assetDto, DecommissionedAssetQuery query)
        {
            //creating the createDecommissionedAsset from the assetDto
            var createDecommissionedAsset = _mapper.Map <CreateDecommissionedAsset>(assetDto);

            //adding network graph, person who decommissioned, and date decommissioned to decommissioned asset info
            createDecommissionedAsset.NetworkPortGraph   = query.NetworkPortGraph;
            createDecommissionedAsset.Decommissioner     = query.Decommissioner;
            createDecommissionedAsset.DateDecommissioned = DateTime.Now;
            var jsonString = JsonConvert.SerializeObject(createDecommissionedAsset);
            //creating a new decommissionedAssetDto + filling in the data
            var decommissionedAsset = _mapper.Map <DecommissionedAssetDto>(createDecommissionedAsset);

            decommissionedAsset.Data = jsonString;
            return(decommissionedAsset);
        }
        private async Task <ActionResult> DecommissionBladeChangePlan(AssetDto chassis, DecommissionedAssetQuery query)
        {
            var changePlanId    = query.ChangePlanId ?? Guid.Empty;
            var changePlanItems = await _changePlanService.GetChangePlanItemsAsync(changePlanId);

            var assetDto = await _assetService.GetAssetAsync(chassis.Id);

            //decommissioning all the current blades in the chassis
            if (assetDto != null && assetDto.Blades != null)
            {
                foreach (AssetDto blade in assetDto.Blades)
                {
                    var item = await _changePlanService.GetChangePlanItemAsync(query.ChangePlanId ?? Guid.Empty, blade.Id);

                    if (item != null)
                    {
                        continue;
                    }                               //if item != null, there's an updated version which exists and will be decommissioned below
                    var decommissionedAsset = CreateDecommissionedAsset(blade, query);
                    await _changePlanService.CreateChangePlanItemAsync(changePlanId, blade.Id, decommissionedAsset);
                }
            }
            //decommissioning the rest of the blades (in the change plan items)
            foreach (ChangePlanItemDto changePlanItem in changePlanItems)
            {
                var newAssetDto = new AssetDto();
                if (changePlanItem.ExecutionType.Equals("create"))
                {
                    var updatedAssetApi = JsonConvert.DeserializeObject <CreateAssetApiDto>(changePlanItem.NewData);
                    newAssetDto = _mapper.Map <AssetDto>(updatedAssetApi);
                }
                else if (changePlanItem != null && changePlanItem.ExecutionType.Equals("update"))
                {
                    var updatedAssetApi = JsonConvert.DeserializeObject <UpdateAssetApiDto>(changePlanItem.NewData);
                    newAssetDto = _mapper.Map <AssetDto>(updatedAssetApi);
                }
                if (newAssetDto.ChassisId != query.Id) //this change plan item is not part of the chassis' blades
                {
                    continue;
                }
                //var decommissionAssetExists = _changePlanService.GetChangePlanItemAsync(newAssetDto.Id);
                var updateadAssetDto = await _changePlanService.FillFieldsInAssetApiForChangePlans(newAssetDto);

                var  decommissionedAsset = CreateDecommissionedAsset(updateadAssetDto, query);
                Guid assetId             = changePlanItem.AssetId;
                if (assetId == Guid.Empty)
                {
                    assetId = changePlanItem.Id;
                }
                await _changePlanService.CreateChangePlanItemAsync(changePlanId, assetId, decommissionedAsset);
            }
            return(Ok());
        }
        private async Task <ActionResult> DecommissionBladeChassis(AssetDto assetDto, DecommissionedAssetQuery query)
        {
            if (assetDto.Blades != null)
            {
                return(Ok());
            }
            foreach (AssetDto blade in assetDto.Blades)
            {
                var decommissionedAsset = CreateDecommissionedAsset(blade, query);
                await _assetService.DeleteAssetAsync(blade.Id);

                await _assetService.CreateDecommissionedAssetAsync(decommissionedAsset);
            }
            return(Ok());
        }