private JObject _tryCreateTempMaterial(Int32 MaterialNodeTypeId, CswPrimaryKey SupplierId, string TradeName, string PartNo, string NodeId, bool IsConstituent) { JObject Ret = new JObject(); NewMaterial PotentialMaterial = new NewMaterial(_CswNbtResources, MaterialNodeTypeId, TradeName, SupplierId, IsConstituent, PartNo, NodeId); bool MaterialExists = PotentialMaterial.existsInDb(); Ret["materialexists"] = MaterialExists; if (false == MaterialExists) { CswNbtPropertySetMaterial NodeAsMaterial = PotentialMaterial.Node; if (null == NodeAsMaterial) { NodeAsMaterial = PotentialMaterial.commit(); } if (null != NodeAsMaterial) { Ret["materialid"] = NodeAsMaterial.NodeId.ToString(); Ret["tradename"] = NodeAsMaterial.TradeName.Text; Ret["partno"] = NodeAsMaterial.PartNumber.Text; Ret["supplier"] = false == IsConstituent ? NodeAsMaterial.Supplier.CachedNodeName : ""; Ret["supplierid"] = false == IsConstituent?SupplierId.ToString() : ""; Ret["nodetypeid"] = NodeAsMaterial.NodeTypeId; NodeAsMaterial.Save.setHidden(value: true, SaveToDb: true); CswNbtSdTabsAndProps SdProps = new CswNbtSdTabsAndProps(_CswNbtResources); Ret["properties"] = SdProps.getProps(NodeAsMaterial.Node, string.Empty, null, CswEnumNbtLayoutType.Add); if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.SDS)) { CswNbtMetaDataObjectClass SDSDocOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.SDSDocumentClass); CswNbtMetaDataNodeType SDSNodeType = SDSDocOC.FirstNodeType; if (null != SDSNodeType) { Ret["documenttypeid"] = SDSNodeType.NodeTypeId; } } Ret["noderef"] = NodeAsMaterial.Node.NodeLink; //for the link } } else { CswNbtPropertySetMaterial ExisitingMaterial = PotentialMaterial.existingMaterial(); Ret["noderef"] = ExisitingMaterial.Node.NodeLink; } return(Ret); }
private CswNbtNode _commitMaterialNode(JObject MaterialObj) { CswNbtNode Ret = null; Int32 MaterialNodeTypeId = CswConvert.ToInt32(MaterialObj["materialnodetypeid"]); if (Int32.MinValue != MaterialNodeTypeId) { CswNbtMetaDataNodeType MaterialNt = _CswNbtResources.MetaData.getNodeType(MaterialNodeTypeId); if (null != MaterialNt) { Ret = _CswNbtResources.Nodes[CswConvert.ToString(MaterialObj["materialId"])]; if (null != Ret) { // Set the Vendor node property isTemp = false if necessary bool IsConstituent = CswConvert.ToBoolean(MaterialObj["isConstituent"]); CswPrimaryKey VendorNodePk = CswConvert.ToPrimaryKey(CswConvert.ToString(MaterialObj["supplierid"])); if (CswTools.IsPrimaryKey(VendorNodePk) && false == IsConstituent) { CswNbtObjClassVendor VendorNode = _CswNbtResources.Nodes.GetNode(VendorNodePk); if (null != VendorNode && VendorNode.IsTemp) { VendorNode.PromoteTempToReal(); } } //Ret.IsTemp = false; JObject MaterialProperties = (JObject)MaterialObj["properties"]; CswNbtSdTabsAndProps SdTabsAndProps = new CswNbtSdTabsAndProps(_CswNbtResources); SdTabsAndProps.saveProps(Ret.NodeId, Int32.MinValue, MaterialProperties, Ret.NodeTypeId, null, IsIdentityTab: false, setIsTempToFalse: false); NewMaterial FinalMaterial = new NewMaterial(_CswNbtResources, Ret); FinalMaterial.TradeName = CswConvert.ToString(MaterialObj["tradename"]); if (false == IsConstituent) { FinalMaterial.SupplierId = CswConvert.ToPrimaryKey(CswConvert.ToString(MaterialObj["supplierid"])); FinalMaterial.PartNo = CswConvert.ToString(MaterialObj["partno"]); } CswNbtPropertySetMaterial NodeAsMaterial = FinalMaterial.commit(); NodeAsMaterial.Save.setHidden(value: false, SaveToDb: true); JObject RequestObj = CswConvert.ToJObject(MaterialObj["request"]); if (RequestObj.HasValues) { _processRequest(CswConvert.ToString(RequestObj["requestitemid"]), NodeAsMaterial); } CswNbtActReceiving Receiving = new CswNbtActReceiving(_CswNbtResources); CswPrimaryKey SDSNodeId = new CswPrimaryKey(); if (null != MaterialObj["sdsDocId"]) { SDSNodeId.FromString(MaterialObj["sdsDocId"].ToString()); JObject SDSProps = CswConvert.ToJObject(MaterialObj["sdsDocProperties"]); Receiving.commitSDSDocNode(NodeAsMaterial.NodeId, SDSNodeId, SDSProps); } Ret.PromoteTempToReal(); } } if (null == Ret) { throw new CswDniException(CswEnumErrorType.Error, "Failed to create new material.", "Attempted to call _commitMaterialNode failed."); } } return(Ret); }