private static AssetDetails MapAssetDetails(CatalogItemDetails dataModel, CatalogDetails catalog) { var returnObj = new AssetDetails(); if (dataModel == null || dataModel.CatalogItemInfo == null) { return(returnObj); } returnObj.ID = dataModel.CatalogItemInfo.ItemID; returnObj.AccountItemID = dataModel.CatalogItemInfo.AccountItemID; returnObj.ImageURL = dataModel.CatalogItemInfo.ImageUrl; returnObj.Name = dataModel.CatalogItemInfo.Description; returnObj.DetailURL = dataModel.CatalogItemInfo.DetailUrl; returnObj.DateIntroduced = dataModel.CatalogItemInfo.DateIntroduced; returnObj.DateLastUpdated = dataModel.CatalogItemInfo.LastUpdate; returnObj.Status = dataModel.CatalogItemInfo.Disabled ? "Inactive" : "Active"; returnObj.ExcludedFromRecommendations = dataModel.CatalogItemInfo.ExcludedFromRecommendations; if (catalog != null) { returnObj.CatalogName = catalog.Name; returnObj.CatalogID = catalog.CatalogId; returnObj.CatalogImage = catalog.Icon_FileName; } return(returnObj); }
public static AssetDetailsViewModel GetCatalogAssetDetails(string catalogID, string accountItemID) { CatalogItemDetails dataModel = CatalogModel.GetCatalogItem(catalogID, accountItemID); CatalogDetails catalog = CatalogModel.GetCatalogDetails(catalogID); var vm = new AssetDetailsViewModel { Details = MapAssetDetails(dataModel, catalog) }; if (string.IsNullOrEmpty(vm.Details.AccountItemID)) { vm.Details.AccountItemID = accountItemID; } if (string.IsNullOrEmpty(vm.Details.CatalogID)) { vm.Details.CatalogID = catalogID; } return(vm); }
public static CatalogItemDetails GetCatalogItem(string catalogID, string accountItemID) { CatalogItemDetails details = null; try { using (_certonaService = new CertonaServiceClient()) { try { UserDTO user = FormsAuthenticationWrapper.User; var catalogItemRequest = new GetCatalogItemRequest() { User = user, AccountID = user.LastAccountID, AccountItemID = accountItemID, CatalogID = catalogID }; var catalogItemResponse = _certonaService.GetCatalogItem(catalogItemRequest); if (catalogItemResponse.Success && catalogItemResponse.CatalogItem != null) { details = new CatalogItemDetails() { CatalogAssociatedItems = catalogItemResponse.CatalogItem.CatalogItemAssociatedItem.Select( r => new ItemAssociatedItem { ItemID = r.ItemID, DisplayOrder = r.DisplayOrder }).ToList() }; if (catalogItemResponse.CatalogItem.CatalogItemInfo != null) { details.CatalogItemInfo = new ItemInfo(catalogItemResponse.CatalogItem.CatalogItemInfo); } details.CatalogItemMetaData = catalogItemResponse.CatalogItem.CatalogItemMetaData.Select( r => new ItemMetaData { CatalogID = r.CatalogID, FunctionName = r.FunctionName, LevelName = r.LevelName, GroupName = r.GroupName }).ToList(); details.CatalogMetaData = catalogItemResponse.CatalogItem.CatalogMetaData.Select( r => new MetaData { CatalogID = r.CatalogID, Name1 = r.Name1, Name2 = r.Name2, Name3 = r.Name3 }).ToList(); details.CatalogMetaData2 = catalogItemResponse.CatalogItem.CatalogMetaData2.Select( r => new MetaData { CatalogID = r.CatalogID, Name1 = r.Name1, Name2 = r.Name2, Name3 = r.Name3 }).ToList(); details.CatalogMapping = catalogItemResponse.CatalogItem.CatalogMapping.Select( r => new CatalogMapping { CatalogID = r.CatalogID, ResonanceField = r.ResonanceField, CustomerField = r.CustomerField, Description = r.Description, AttributeType = r.AttributeType, CustomVariable = r.CustomVariable, IsRuleEnabled = r.IsRuleEnabled, IsMapped = r.IsMapped, XSLTransform = r.XSLTransform, OLAPLevel = r.OLAPLevel }).ToList(); } } catch (TimeoutException exception) { _certonaService.Abort(); throw; } catch (CommunicationException exception) { _certonaService.Abort(); throw; } } } catch (Exception ex) { throw; } return(details); }
public static AssetDetailsViewModel GetCatalogAssetDetailsWithMapping(string catalogID, string accountItemID) { CatalogItemDetails dataModel = CatalogModel.GetCatalogItem(catalogID, accountItemID); CatalogDetails catalog = CatalogModel.GetCatalogDetails(catalogID); AssetDetails details = MapAssetDetails(dataModel, catalog); if (string.IsNullOrEmpty(details.AccountItemID)) { details.AccountItemID = accountItemID; } if (string.IsNullOrEmpty(details.CatalogID)) { details.CatalogID = catalogID; } AssetAdditionalDetails additionalDetails = new AssetAdditionalDetails(); // Dictionary Keys come from dataModel.CatalogMapping foreach (var catalogMapping in dataModel.CatalogMapping.OrderBy(c => c.CustomerField)) { additionalDetails.Details.Add(catalogMapping.ResonanceField, new CatalogAssetMapping() { DisplayLabel = catalogMapping.CustomerField, AttributeType = catalogMapping.AttributeType, DisplayValues = new List <string>() }); } // now we have map, need to iterate through CatalogItemMetadata foreach (var item in dataModel.CatalogItemMetaData) { // look up function name, then add to Display values as needed if if (additionalDetails.Details.ContainsKey(item.FunctionName)) { // get object by key and update CatalogAssetMapping objValue = null; if (additionalDetails.Details.TryGetValue(item.FunctionName, out objValue)) { objValue.DisplayValues.Add(item.GroupName); objValue.DisplayValues.Sort(); } } } // map using Reflection if (dataModel.CatalogItemInfo != null) { PropertyInfo[] propertyInfos = dataModel.CatalogItemInfo.GetType().GetProperties(); for (int i = 0; i < propertyInfos.Length; i++) { var key = propertyInfos[i].Name; // list of exceptions (these values have scheme names with _ but have been stripped out of the key) switch (propertyInfos[i].Name) { case "ItemID": key = "Item_ID"; break; case "AccountID": key = "Account_ID"; break; case "AccountItemID": key = "Account_Item_ID"; break; case "ObjectID": key = "Object_ID"; break; case "CatalogID": key = "Catalog_ID"; break; case "ImageURL": key = "Image_URL"; break; case "DetailURL": key = "Detail_URL"; break; } if (additionalDetails.Details.ContainsKey(key)) //|| additionalDetails.Details.ContainsKey(key2)) { CatalogAssetMapping objValue = null; // see if property is mapped, if so, then add the value // if (additionalDetails.Details.TryGetValue(propertyInfos[i].Name, out objValue)) if (additionalDetails.Details.TryGetValue(key, out objValue)) { // get the property value var obj = propertyInfos[i].GetValue(dataModel.CatalogItemInfo, null); if (obj != null) { objValue.DisplayValues.Add(obj.ToString()); objValue.DisplayValues.Sort(); } } } } } return(new AssetDetailsViewModel { Details = details, AdditionalDetails = additionalDetails }); }