private static void CBOMV2CatalogData2Model(List <CBOMV2Model.CBOMV2Catalog> catalogRecords, CatalogModel currentNode) { List <CBOMV2Model.CBOMV2Catalog> subRecords = (from q in catalogRecords where q.ParentHieId == currentNode.CBOMV2HieID && Convert.ToBoolean(q.isVisible) orderby q.SeqNo, q.CatalogName select q).ToList(); if (subRecords.Count == 0) { return; } foreach (CBOMV2Model.CBOMV2Catalog subRecord in subRecords) { CatalogModel subModel = new CatalogModel(subRecord.Id, subRecord.CategoryId, subRecord.ImageId, 2, subRecord.SalesOrg, subRecord.CBOMOrg, subRecord.CatalogName, subRecord.CatalogDesc, subRecord.CatalogType, subRecord.HieId); currentNode.Children.Add(subModel); CBOMV2CatalogData2Model(catalogRecords, subModel); } }
public static CatalogModel GetCBOMV2CatalogModel(string salesOrg, string cbomOrg, string companyId) { // 1. Get all records include Root, catalogs, components from DB List <CBOMV2Model.CBOMV2Catalog> catalogRecords = CBOMV2Model.GetCBOMV2CatalogRecords(salesOrg, cbomOrg, companyId); CBOMV2Model.CBOMV2Catalog rootRecord = catalogRecords.Where(d => d.CatalogName.Equals(cbomOrg + "_Root")).FirstOrDefault(); catalogRecords.RemoveAll(d => d.CatalogType == CatalogType.Component && !isPartOrdereable((d.CatalogName.Contains("/") ? d.CatalogName.Split('/')[0] : d.CatalogName), salesOrg)); // 2. Convert DB records to standard ViewModel CatalogModel CatalogModel rootModel = new CatalogModel(rootRecord.Id, "", "", 2, salesOrg, cbomOrg, rootRecord.CatalogName, "", CatalogType.Root, rootRecord.HieId); if (catalogRecords != null && catalogRecords.Count > 0) { CBOMV2CatalogData2Model(catalogRecords, rootModel); } return(rootModel); }