Example #1
0
        /// <summary>
        /// convert project part to part price
        /// </summary>
        /// <param name="projectPart"></param>
        /// <returns></returns>
        public IV00108_Part_Price ConvertToCreatePrice(ProjectPart projectPart)
        {
            IV00108_Part_Price part = new IV00108_Part_Price();

            part.ITEMNMBR = projectPart.Number;
            part.PRCLEVEL = "STANDARD";
            part.UOFM     = "part";

            return(part);
        }
Example #2
0
        /// <summary>
        /// get part price by item number
        /// </summary>
        /// <param name="itemNumber"></param>
        /// <returns></returns>
        public IV00108_Part_Price GetPartPrice(string itemNumber)
        {
            var part = new IV00108_Part_Price();

            try
            {
                part = _dynamicsContext.IV00108_Part_Price.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == itemNumber.Replace(" ", string.Empty).ToLower());
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting part price: {0} ", ex.ToString());
            }

            return(part);
        }
Example #3
0
        /// <summary>
        /// save new part price
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public OperationResult SavePartPrice(IV00108_Part_Price part)
        {
            var operationResult = new OperationResult();

            var existingPart = _dynamicsContext.IV00108_Part_Price.FirstOrDefault(x => x.ITEMNMBR.Replace(" ", string.Empty).ToLower() == part.ITEMNMBR.Replace(" ", string.Empty).ToLower());

            if (existingPart == null)
            {
                logger.Debug("Part Price is being created...");

                using (eConnectMethods e = new eConnectMethods())
                {
                    try
                    {
                        // Instantiate a taIVCreateItemPriceListLine_ItemsTaIVCreateItemPriceListLine XML node object
                        taIVCreateItemPriceListLine_ItemsTaIVCreateItemPriceListLine item = new taIVCreateItemPriceListLine_ItemsTaIVCreateItemPriceListLine();

                        //Populate elements of the taIVCreateItemPriceListLine_ItemsTaIVCreateItemPriceListLine XML node object
                        item.ITEMNMBR       = part.ITEMNMBR;
                        item.PRCLEVEL       = part.PRCLEVEL;
                        item.UOFM           = part.UOFM;
                        item.UpdateIfExists = 0;

                        // Instantiate a IVItemMasterType schema object
                        IVItemMasterType itemtype = new IVItemMasterType();

                        // Populate the IVItemMasterType schema with the taIVCreateItemPriceListLine_ItemsTaIVCreateItemPriceListLine XML node
                        itemtype.taIVCreateItemPriceListLine_Items = new taIVCreateItemPriceListLine_ItemsTaIVCreateItemPriceListLine[1] {
                            item
                        };
                        IVItemMasterType[] itemMaster = { 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 = itemMaster;

                        // 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 price header: {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 price header: {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);
        }