/// <summary> /// convert part model to part currency for update part currency /// </summary> /// <param name="model"></param> /// <returns></returns> public IV00105_Part_Currency ConvertToUpdateCurrency(PartOperationModel model) { IV00105_Part_Currency partCurrency = new IV00105_Part_Currency(); partCurrency.ITEMNMBR = model.PartNumber; partCurrency.LISTPRCE = model.Price; partCurrency.CURNCYID = string.Empty; return(partCurrency); }
/// <summary> /// convert project part to part currency /// </summary> /// <param name="projectPart"></param> /// <returns></returns> public IV00105_Part_Currency ConvertToCreateCurrency(ProjectPart projectPart) { IV00105_Part_Currency part = new IV00105_Part_Currency(); part.ITEMNMBR = projectPart.Number; part.CURNCYID = string.Empty; part.LISTPRCE = projectPart.Price; return(part); }
/// <summary> /// update part vendor master /// </summary> /// <param name="part"></param> /// <returns></returns> public OperationResult UpdatePartVendorMaster(IV00105_Part_Currency part) { var operationResult = new OperationResult(); var existingPart = _dynamicsContext.IV00105_Part_Currency.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == part.ITEMNMBR.Replace(" ", string.Empty).ToLower()); if (existingPart != null) { logger.Debug("Part Currency is being updated."); using (eConnectMethods e = new eConnectMethods()) { try { using (SqlConnection connection = new SqlConnection(_dynamicsConnection)) { connection.Open(); SqlCommand cmd = new SqlCommand("UPDATE dbo.IV00105 SET LISTPRCE = @ListPrice WHERE ITEMNMBR = @ItemNumber"); cmd.CommandType = CommandType.Text; cmd.Connection = connection; cmd.Parameters.AddWithValue("@ItemNumber", part.ITEMNMBR); cmd.Parameters.AddWithValue("@ListPrice", part.LISTPRCE); cmd.ExecuteNonQuery(); connection.Close(); } operationResult.Success = true; operationResult.Message = "Success"; } // 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 updating part currency: {0} ", ex.ToString()); } } // end of using statement } else { operationResult.Success = false; operationResult.Message = "Unable to find selected part currency."; } return(operationResult); }
/// <summary> /// get part currency by item number /// </summary> /// <param name="itemNumber"></param> /// <returns></returns> public IV00105_Part_Currency GetPartCurrency(string itemNumber) { var part = new IV00105_Part_Currency(); try { part = _dynamicsContext.IV00105_Part_Currency.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == itemNumber.Replace(" ", string.Empty).ToLower()); } catch (Exception ex) { logger.ErrorFormat("Error getting part currency: {0} ", ex.ToString()); } return(part); }
/// <summary> /// save new part currency /// </summary> /// <param name="part"></param> /// <returns></returns> public OperationResult SavePartCurrency(IV00105_Part_Currency part) { var operationResult = new OperationResult(); var existingPart = _dynamicsContext.IV00105_Part_Currency.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == part.ITEMNMBR.Replace(" ", string.Empty).ToLower()); if (existingPart == null) { logger.Debug("Master Part is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { // Instantiate a taUpdateCreateItemRcd XML node object taUpdateCreateItemCurrencyRcd_ItemsTaUpdateCreateItemCurrencyRcd item = new taUpdateCreateItemCurrencyRcd_ItemsTaUpdateCreateItemCurrencyRcd(); //Populate elements of the taUpdateCreateItemRcd XML node object item.ITEMNMBR = part.ITEMNMBR; //item.CURNCYID = part.CURNCYID; item.UpdateIfExists = 0; // Instantiate a IVItemMasterType schema object IVItemMasterType itemtype = new IVItemMasterType(); // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node itemtype.taUpdateCreateItemCurrencyRcd_Items = new taUpdateCreateItemCurrencyRcd_ItemsTaUpdateCreateItemCurrencyRcd[1] { item }; IVItemMasterType[] currencyItem = { itemtype }; // 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 IVItemMasterType schema object eConnect.IVItemMasterType = currencyItem; // 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.CreateEntity(_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 saving new part: {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 saving new part: {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 = "Duplicate Entry"; } return(operationResult); }