public EST_DataExportModel GetExportData(IQueryBuilder queryBuilder) { var returnValue = new EST_DataExportModel(); _queryBuilder = SetDefaultValues(queryBuilder); string whereExpression = "WHERE [Part_Type] = 'R' AND [PART_DESC] NOT LIKE '%**%' "; _queryBuilder.WhereExpression = whereExpression; // Build the Query _sCAuditService.QueryBuilderObject = _queryBuilder; _sCDeployService.QueryBuilderObject = _queryBuilder; // Get the data var returnAuditList = GetData_Audit_BaseQuery(); var returnDeployList = GetData_Deploy_BaseQuery(); // Cleanse, Reduce and subset data returnValue.NewItemList = Get_New_Item(returnAuditList); returnValue.LocationChangeList = Get_Location_Change(returnAuditList); returnValue.AssetTagChangeList = Get_Asset_Tag_Change(returnAuditList); returnValue.DeployedToBAMUserList = Get_Deployed_to_BAM_User(returnDeployList); //returnValue.ReturnedFromBAMUserList = Get_Returned_from_BAM_User(returnDeployList); Depreciated returnValue.ReturnedFromBAMList = Get_ReturnedFromBAM(returnAuditList); returnValue.RetiredAssetList = Get_RetiredAsset(returnAuditList); returnValue.DisplosedAssetList = Get_DisplosedAsset(returnAuditList); returnValue.SwappedAssetList = Get_SwappedAsset(returnDeployList); return(returnValue); }
internal async Task <EST_DataExportModel> Process_DisplosedAssetList(EST_DataExportModel model, ServiceProgressReportBsm serviceProgressReport) { if (model == null) { return(model); } var returnList = new List <SCAuditBsm>(); model.DisplosedAssetList.ToList().ForEach(asset => { HardwareTemplate_Full newHardwareAsset; var bamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (bamTemplate != null) { newHardwareAsset = CloneObject.Clone(bamTemplate); } else { newHardwareAsset = CreateNewItem(asset); } newHardwareAsset.OwnedBy = null; newHardwareAsset.Target_HardwareAssetHasCostCenter = null; newHardwareAsset = _hardwareAssetService.SetHardwareAssetStatus(newHardwareAsset, EST_HWAssetStatus.Disposed); newHardwareAsset.Target_HardwareAssetHasLocation = null; newHardwareAsset.DisposalDate = DateTime.Now; newHardwareAsset.DisposalReference = "Esteem"; _hardwareAssetService.UpdateTemplate(newHardwareAsset, bamTemplate); // Check Update was successful var updatedbamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (updatedbamTemplate?.Target_HardwareAssetHasLocation?.DisplayName != "Esteem") { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.Disposed, SCAudit_Item = asset, BAM_HardwareTemplate_Exception = updatedbamTemplate, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } _billables.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.Disposed, SCAudit_Item = asset, BAM_HardwareTemplate_Exception = updatedbamTemplate, }); }); model.DisplosedAssetList = returnList; return(model); }
internal async Task <EST_DataExportModel> Process_NewItemList(EST_DataExportModel model, ServiceProgressReportBsm serviceProgressReport) { if (model == null) { return(model); } var returnList = new List <SCAuditBsm>(); model.NewItemList.ToList().ForEach(asset => { // Check the Item doesn't already exist in the system var existingBamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); // If so.. add it to the Updates - Change Location List if (existingBamTemplate != null && existingBamTemplate.Target_HardwareAssetHasLocation?.DisplayName != "Esteem") { model.LocationChangeList.Add(asset); return; } else if (existingBamTemplate != null) { return; } // Create New Item Template - set default values HardwareTemplate_Full bamTemplate = CreateNewItem(asset); var hasModelRecord = false; bamTemplate = _BAM_ModelLookupService.SetModelData(bamTemplate, asset.Asset_Desc, out hasModelRecord); if (hasModelRecord) { var returnItems = _hardwareAssetService.InsertTemplate(bamTemplate).FirstOrDefault(); } var updatedbamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (updatedbamTemplate == null) { if (updatedbamTemplate?.Target_HardwareAssetHasLocation?.DisplayName != "Esteem") { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.NewItem, SCAudit_Item = asset, BAM_HardwareTemplate_Exception = updatedbamTemplate, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } } }); return(model); }
internal async Task <EST_DataExportModel> Process_LocationChangeList(EST_DataExportModel model, ServiceProgressReportBsm serviceProgressReport) { if (model == null) { return(model); } var returnList = new List <SCAuditBsm>(); model.LocationChangeList.ToList().ForEach(asset => { HardwareTemplate_Full newHardwareAsset; var bamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); // If the Location is already set to Esteem then do nothing if (bamTemplate != null && bamTemplate.Target_HardwareAssetHasLocation?.DisplayName == "Esteem") { return; } if (bamTemplate != null) { newHardwareAsset = CloneObject.Clone(bamTemplate); } else { newHardwareAsset = CreateNewItem(asset); } newHardwareAsset = _hardwareAssetService.SetLocation(newHardwareAsset, asset.Audit_Dest_Site_Num); _hardwareAssetService.UpdateTemplate(newHardwareAsset, bamTemplate); // Check Update was successful var updatedbamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (updatedbamTemplate?.Target_HardwareAssetHasLocation?.DisplayName != "Esteem") { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.LocationChanged, SCAudit_Item = asset, BAM_HardwareTemplate_Exception = newHardwareAsset, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } }); model.LocationChangeList = returnList; return(model); }
internal async Task <EST_DataExportModel> Process_AssetTagChangeList(EST_DataExportModel model, ServiceProgressReportBsm serviceProgressReport) { if (model == null) { return(model); } var returnList = new List <SCAuditBsm>(); model.AssetTagChangeList.ToList().ForEach(asset => { HardwareTemplate newHardwareAsset; var bamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); // If the Asset isn't null and the Tag is already correct then just return if (bamTemplate != null && bamTemplate.AssetTag == asset.Audit_Part_Num) { return; } else if (bamTemplate != null) { newHardwareAsset = CloneObject.Clone(bamTemplate); } else { newHardwareAsset = CreateNewItem(asset); } newHardwareAsset = _hardwareAssetService.SetAssetTag(newHardwareAsset, asset.Audit_Part_Num); _hardwareAssetService.UpdateTemplate(newHardwareAsset, bamTemplate); // Check Update was successful var updatedbamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (updatedbamTemplate?.AssetTag != asset.Audit_Part_Num) { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.AssetTagChanged, SCAudit_Item = asset, BAM_HardwareTemplate_Exception = updatedbamTemplate, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } }); model.AssetTagChangeList = returnList; return(model); }
private List <SCAudit> GetAll_BaseQuery() { var returnValue = new EST_DataExportModel(); returnValue = _eST_Service.GetExportData(_queryBuilder); if (returnValue.Any()) { returnValue = returnValue .Where ( item => item.Audit_Part_Num.ToUpper().StartsWith("BNL") && item.Audit_Rem.StartsWith("Added PO") && (item.Audit_Dest_Site_Num.ToUpper().StartsWith("E-") || item.Audit_Dest_Site_Num.ToUpper() == "LTX") ) .ToList(); } return(returnValue); }
internal async Task <EST_DataExportModel> Process_SwappedAssetList(EST_DataExportModel model, ServiceProgressReportBsm serviceProgressReport) { if (model == null) { return(model); } var returnList = new List <SCAuditDeployBsm>(); model.SwappedAssetList.ToList().ForEach(asset => { #region Deploy Process HardwareTemplate_Full newHardwareAsset; var bamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (bamTemplate != null) { newHardwareAsset = CloneObject.Clone(bamTemplate); } else { newHardwareAsset = CreateNewItem(asset); } #region Deploy newHardwareAsset.Target_HardwareAssetHasLocation = null; newHardwareAsset = _hardwareAssetService.SetHardwareAssetStatus(newHardwareAsset, EST_HWAssetStatus.Deployed); newHardwareAsset.OwnedBy = newHardwareAsset.OwnedBy; newHardwareAsset.Target_HardwareAssetHasCostCenter = newHardwareAsset.Target_HardwareAssetHasCostCenter; newHardwareAsset.AssetTag = asset.AssetTag; newHardwareAsset.Name = asset.AssetTag; newHardwareAsset.DisplayName = asset.AssetTag; _hardwareAssetService.UpdateTemplate(newHardwareAsset, bamTemplate); #endregion Deploy // Check Deployed Update was successful var updatedDeployedTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (updatedDeployedTemplate?.Target_HardwareAssetHasLocation?.DisplayName == "Esteem") { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = updatedDeployedTemplate.SerialNumber, AssetStatus = EST_HWAssetStatus.Deployed, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = updatedDeployedTemplate, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } _billables.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = updatedDeployedTemplate.SerialNumber, AssetStatus = EST_HWAssetStatus.Deployed, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = updatedDeployedTemplate, }); #endregion Deploy Process #region Return Process HardwareTemplate_Full newReturnedHardwareAsset; var returnedBamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumberReturned).FirstOrDefault(); if (returnedBamTemplate != null) { newReturnedHardwareAsset = CloneObject.Clone(returnedBamTemplate); } else { newReturnedHardwareAsset = CreateNewItem(asset); } #region Returned newReturnedHardwareAsset.OwnedBy = null; newReturnedHardwareAsset.Target_HardwareAssetHasCostCenter = null; newReturnedHardwareAsset = _hardwareAssetService.SetHardwareAssetStatus(newReturnedHardwareAsset, EST_HWAssetStatus.Returned); newReturnedHardwareAsset = _hardwareAssetService.SetLocation(newReturnedHardwareAsset, "Esteem"); _hardwareAssetService.UpdateTemplate(newReturnedHardwareAsset, returnedBamTemplate); #endregion Returned // Check Returned Update was successful var updatedReturnedTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumberReturned).FirstOrDefault(); if (updatedReturnedTemplate?.Target_HardwareAssetHasLocation?.DisplayName != "Esteem") { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = updatedReturnedTemplate.SerialNumber, AssetStatus = EST_HWAssetStatus.Returned, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = updatedDeployedTemplate, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } _billables.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = updatedReturnedTemplate.SerialNumber, AssetStatus = EST_HWAssetStatus.Returned, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = updatedReturnedTemplate, }); #endregion Return Process }); model.SwappedAssetList = returnList; return(model); }
internal async Task <EST_DataExportModel> Process_DeployedToBAMUserList(EST_DataExportModel model, ServiceProgressReportBsm serviceProgressReport) { if (model == null) { return(model); } var returnList = new List <SCAuditDeployBsm>(); model.DeployedToBAMUserList.ToList().ForEach(asset => { HardwareTemplate_Full newHardwareAsset; if (string.IsNullOrEmpty(asset.RequestUser)) { returnList.Add(asset); return; } var bamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); var user = _hardwareAssetService.GetUser(asset.RequestUser); if (user == null || !user.Name.Contains(asset.RequestUser)) { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.Deployed, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = bamTemplate, ExceptionMessage = "No User Found in BAM" }); returnList.Add(asset); return; } // The asset is not null and User is correct, HardwareStatus is Deployed and location is null then return if (bamTemplate != null && bamTemplate?.OwnedBy != null && (bool)bamTemplate?.OwnedBy?.DisplayName?.Contains(user?.Name) && bamTemplate?.HardwareAssetStatus?.Name == EST_HWAssetStatus.Deployed.ToBAMString() && bamTemplate?.AssetTag == asset.AssetTag && bamTemplate?.Name == asset.AssetTag && bamTemplate?.DisplayName == asset.AssetTag && bamTemplate?.Target_HardwareAssetHasLocation == null) { return; } else if (bamTemplate != null) { newHardwareAsset = CloneObject.Clone(bamTemplate); } else { newHardwareAsset = CreateNewItem(asset); } newHardwareAsset.Target_HardwareAssetHasLocation = null; newHardwareAsset = _hardwareAssetService.SetHardwareAssetStatus(newHardwareAsset, EST_HWAssetStatus.Deployed); newHardwareAsset = _hardwareAssetService.SetUser(newHardwareAsset, user); newHardwareAsset = _hardwareAssetService.SetCostCode(newHardwareAsset, asset.CostCode); newHardwareAsset.AssetTag = asset.AssetTag; newHardwareAsset.Name = asset.AssetTag; newHardwareAsset.DisplayName = asset.AssetTag; _hardwareAssetService.UpdateTemplate(newHardwareAsset, bamTemplate); // Check Update was successful var updatedbamTemplate = _hardwareAssetService.GetHardwareAsset_Full(asset.SerialNumber).FirstOrDefault(); if (!(bool)updatedbamTemplate?.OwnedBy?.DisplayName?.Contains(asset.RequestUser)) { _reportings.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.Deployed, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = updatedbamTemplate, ExceptionMessage = "Failed to Update" }); returnList.Add(asset); } _billables.Add(new BAM_ReportingBsm() { ServiceProgressReportId = serviceProgressReport.Id, SerialNumber = asset.SerialNumber, AssetStatus = EST_HWAssetStatus.Deployed, SCAuditDeploy_Item = asset, BAM_HardwareTemplate_Exception = updatedbamTemplate, }); }); model.DeployedToBAMUserList = returnList; return(model); }