public void promoteTempToRealTestTempStateRemoved() { CswNbtNode TestNode = TestData.Nodes.createTempNode(); Assert.IsTrue(TestNode.IsTemp); TestNode.PromoteTempToReal(); Assert.IsFalse(TestNode.IsTemp); }
public void Edit(CswNbtAPIReturn Return, CswNbtAPIGenericRequest GenericRequest) { if (hasPermission(GenericRequest, Return)) { try { CswNbtNode Node = _CswNbtResources.Nodes.GetNode(GenericRequest.NodeId); if (null != Node && GenericRequest.MetaDataName == Node.getNodeType().NodeTypeName) { if (null != GenericRequest.ResourceToUpdate) { foreach (string propKey in GenericRequest.ResourceToUpdate.PropertyData.properties.Keys) { CswNbtWcfProperty wcfProp = GenericRequest.ResourceToUpdate.PropertyData.properties[propKey]; ReadPropertyData(Node, wcfProp); } } if (Node.IsTemp) { Node.PromoteTempToReal(); } else { Node.postChanges(false); } } else { Return.Status = HttpStatusCode.NotFound; } } catch (Exception) { Return.Status = HttpStatusCode.InternalServerError; } } else { Return.Status = HttpStatusCode.Forbidden; } }
public void promoteTempToRealTestCompoundUniqueViolation() { TestData.Nodes.createVendorNode(); CswNbtNode InvalidVendor = TestData.Nodes.createVendorNode(true); Assert.IsTrue(InvalidVendor.IsTemp); bool posted = false; try { InvalidVendor.PromoteTempToReal(); posted = true; } catch (Exception e) { Assert.IsTrue(e.Message.Contains("The following properties must have unique values")); } Assert.IsFalse(posted, "No Compound-Unique validation occurred."); }
public CswNbtReceivingDefinition receiveContainers(CswNbtReceivingDefinition ReceiptDef, ref int NodesProcessed, int MaxProcessed) { CswNbtMetaDataNodeType ContainerNt = _CswNbtResources.MetaData.getNodeType(ReceiptDef.ContainerNodeTypeId); foreach (CswNbtAmountsGridQuantity QuantityDef in ReceiptDef.Quantities) { CswNbtObjClassSize AsSize = _CswNbtResources.Nodes.GetNode(QuantityDef.SizeNodeId); string Barcode = string.Empty; Action <CswNbtNode> After = delegate(CswNbtNode NewNode) { CswNbtObjClassContainer thisContainer = NewNode; if (QuantityDef.getNumBarcodes() <= QuantityDef.NumContainers && false == string.IsNullOrEmpty(Barcode)) { thisContainer.Barcode.setBarcodeValueOverride(Barcode, false); } thisContainer.Size.RelatedNodeId = QuantityDef.SizeNodeId; thisContainer.Material.RelatedNodeId = ReceiptDef.MaterialNodeId; if (AsSize.QuantityEditable.Checked != CswEnumTristate.True) { QuantityDef.Quantity = AsSize.InitialQuantity.Quantity; QuantityDef.UnitNodeId = AsSize.InitialQuantity.UnitId; } if (null == thisContainer.Quantity.UnitId || Int32.MinValue == thisContainer.Quantity.UnitId.PrimaryKey) { thisContainer.Quantity.UnitId = QuantityDef.UnitNodeId; } thisContainer.DispenseIn(CswEnumNbtContainerDispenseType.Receive, QuantityDef.Quantity, QuantityDef.UnitNodeId, ReceiptDef.RequestItemtNodeId); thisContainer.Disposed.Checked = CswEnumTristate.False; thisContainer.ReceiptLot.RelatedNodeId = ReceiptDef.ReceiptLotNodeId; }; for (Int32 C = 0; C < QuantityDef.NumContainers; C += 1) { if (NodesProcessed < MaxProcessed) { //we promote the first container before the batch op starts, so there should always be at least one container id in the first set of quantities CswPrimaryKey ContainerId = null; if (C < QuantityDef.ContainerIds.Count) { ContainerId = CswConvert.ToPrimaryKey(QuantityDef.ContainerIds[C]); } CswCommaDelimitedString Barcodes = QuantityDef.getBarcodes(); Barcode = (QuantityDef.getNumBarcodes() > C ? Barcodes[C] : string.Empty); if (null == ContainerId) //only create a container if we haven't already { CswNbtNodeKey ContainerNodeKey; CswNbtObjClassContainer Container = _CswNbtSdTabsAndProps.addNode(ContainerNt, ReceiptDef.ContainerProps, out ContainerNodeKey, After); QuantityDef.ContainerIds.Add(Container.NodeId.ToString()); NodesProcessed++; } else { CswNbtNode InitialContainerNode = _CswNbtResources.Nodes.GetNode(ContainerId); if (null != InitialContainerNode && InitialContainerNode.IsTemp) { _CswNbtSdTabsAndProps.saveNodeProps(InitialContainerNode, ReceiptDef.ContainerProps); After(InitialContainerNode); InitialContainerNode.PromoteTempToReal(); NodesProcessed++; } } } } //for( Int32 C = 0; C < NoContainers; C += 1 ) } return(ReceiptDef); }
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); }