public static CatalogModel GetCBOMV1CatalogModel(string salesOrg, string cbomOrg, string companyId) { // 1. Get DB records List <CBOMV1Model.CBOMV1Catalog> catalogRecords = CBOMV1Model.GetCBOMV1CatalogRecords(salesOrg, cbomOrg); CatalogModel rootModel = new CatalogModel("Root", "", "", 1, salesOrg, cbomOrg, "CatalogRoot", "", CatalogType.Root); // 2. Convert to standard viewmodel CatalogModel // Bottom-up, consider to V1 schema, get all components first, then add catalog records from its parent name. if (catalogRecords != null && catalogRecords.Count > 0) { foreach (CBOMV1Model.CBOMV1Catalog distinctCatalog in catalogRecords.GroupBy(d => d.ParentName).Select(d => d.First())) { CatalogModel catalog = new CatalogModel(distinctCatalog.ParentName, "", "", 1, salesOrg, cbomOrg, distinctCatalog.ParentName, "", CatalogType.Catalog); foreach (CBOMV1Model.CBOMV1Catalog catalogRecord in catalogRecords.Where(d => d.ParentName == catalog.CatalogName && (catalog.CatalogName.Equals("CTOS") ? d.CatalogName.Contains(companyId) : true)).OrderBy(d => d.CatalogName)) { CatalogModel component = new CatalogModel(catalogRecord.Id, catalogRecord.CategoryId, catalogRecord.ImageId, 1, salesOrg, cbomOrg, catalogRecord.CatalogName, catalogRecord.CatalogDesc, CatalogType.Component); catalog.Children.Add(component); } rootModel.Children.Add(catalog); } } return(rootModel); }
public static ConfiguratorModel GetCBOMV1ConfiguratorModel(string rootId, string salesOrg, string cbomOrg) { // 1. Get all records include Root, categories, components from DB List <CBOMV1Model.CBOMV1Category> categoryRecords = CBOMV1Model.GetCBOMV1CategoryRecords(rootId, salesOrg, cbomOrg); categoryRecords.RemoveAll(item => (item.CategoryType == CategoryType.Component || item.CategoryType == CategoryType.SharedComponent) && !isPartOrdereable(item.CategoryName, salesOrg)); CBOMV1Model.CBOMV1Category rootRecord = (from q in categoryRecords where q.Id == rootId select q).ToList().FirstOrDefault(); // 2. Convert DB records to ConfiguratorRecord which contains whole tree structure ConfiguratorRecord rootNode = new ConfiguratorRecord(rootRecord.Id, rootRecord.CategoryName, rootRecord.CategoryDesc, 0, CategoryType.Root, 1, 1, true, false, true, false, ""); CBOMV1Category2Model(categoryRecords, rootNode); // 3. Add rootNode to standard ViewModel ConfiguratorModel ConfiguratorModel rootModel = new ConfiguratorModel(salesOrg, cbomOrg, 1, "", "", rootNode); return(rootModel); }