public static bool UpdateEntity(ref string response, string transactionXML, string companyDB) { string connString = DataAccess.ConnectionStringWindows; bool returnValue; response = ""; eConnectMethods eConnCall = new eConnectMethods(); try { returnValue = eConnCall.UpdateEntity(connString, transactionXML); return(true); } catch (eConnectException ex) { response = ex.Message; return(false); } catch (SqlException ex) { foreach (SqlError sqlErr in ex.Errors) { response += sqlErr.Message + "\r\n"; } return(false); } catch (Exception ex) { response = ex.Message; return(false); } }
/// <summary> /// update foundry /// </summary> /// <param name="foundry"></param> /// <returns></returns> public OperationResult UpdateFoundry(PM00200_Foundry foundry) { var operationResult = new OperationResult(); var existingFoundry = _dynamicsContext.PM00200_Foundry.FirstOrDefault(x => x.VENDORID.Replace(" ", string.Empty) == foundry.VENDORID); if (existingFoundry != null) { logger.Debug("Foundry is being updated."); string sCustomerDocument; string sXsdSchema; string sConnectionString; using (eConnectMethods e = new eConnectMethods()) { try { // Instantiate a taUpdateCreateCustomerRcd XML node object taUpdateCreateVendorRcd vendor = new taUpdateCreateVendorRcd(); //Populate elements of the taUpdateCreateVendorRcd XML node object vendor.VENDORID = foundry.VENDORID; vendor.VENDNAME = foundry.VENDNAME; vendor.VENDSHNM = foundry.VENDSHNM; vendor.UseVendorClass = 0; vendor.UpdateIfExists = 1; // Instantiate a PMVendorMasterType schema object PMVendorMasterType vendortype = new PMVendorMasterType(); // Populate the PMVendorMasterType schema with the taUpdateCreateVendorRcd XML node vendortype.taUpdateCreateVendorRcd = vendor; PMVendorMasterType[] vendorMaster = { vendortype }; // Instantiate an eConnectType schema object eConnectType eConnect = new eConnectType(); // Instantiate a Memory Stream object MemoryStream memoryStream = new MemoryStream(); // Create an XML serializer object XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); // Populate the eConnectType object with the PMVendorMasterType schema object eConnect.PMVendorMasterType = vendorMaster; // Serialize the eConnectType. serializer.Serialize(memoryStream, eConnect); // Reset the position of the memory stream to the start. memoryStream.Position = 0; // Create an XmlDocument from the serialized eConnectType in memory. XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); memoryStream.Close(); // Call eConnect to process the XmlDocument. e.UpdateEntity(_dynamicsConnection, xmlDocument.OuterXml); operationResult.Success = true; operationResult.Message = "Success"; } // The eConnectException class will catch eConnect business logic errors. // display the error message on the console catch (eConnectException exc) { Console.Write(exc.ToString()); operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error while updating foundry: {0} ", exc.ToString()); } // Catch any system error that might occurr. // display the error message on the console catch (System.Exception ex) { Console.Write(ex.ToString()); operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error while updating foundry: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement } else { operationResult.Success = false; operationResult.Message = "Unable to find selected foundry."; } return(operationResult); }