예제 #1
0
        /// <summary>
        /// convert projectPart to part price option
        /// </summary>
        /// <param name="projectPart"></param>
        /// <returns></returns>
        public IV00107_Part_Price_Option ConvertToCreatePriceOption(ProjectPart projectPart)
        {
            IV00107_Part_Price_Option part = new IV00107_Part_Price_Option();

            part.ITEMNMBR = projectPart.Number;
            part.PRCLEVEL = "STANDARD";
            part.UOFM     = "part";
            part.CURNCYID = string.Empty;

            return(part);
        }
예제 #2
0
        /// <summary>
        /// get part price option by item number
        /// </summary>
        /// <param name="itemNumber"></param>
        /// <returns></returns>
        public IV00107_Part_Price_Option GetPartPriceOption(string itemNumber)
        {
            var part = new IV00107_Part_Price_Option();

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

            return(part);
        }
예제 #3
0
        /// <summary>
        /// save new part price option
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public OperationResult SavePartPriceOption(IV00107_Part_Price_Option part)
        {
            var operationResult = new OperationResult();

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

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

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

                        //Populate elements of the taIVCreateItemPriceListHeader XML node object
                        item.ITEMNMBR = part.ITEMNMBR;
                        //item.PRICMTHD = part.PRICMTHD;
                        item.PRCLEVEL       = part.PRCLEVEL;
                        item.UOFM           = part.UOFM;
                        item.CURNCYID       = string.Empty;
                        item.UpdateIfExists = 0;

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

                        // Populate the IVItemMasterType schema with the taIVCreateItemPriceListHeader XML node
                        itemtype.taIVCreateItemPriceListHeader = 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);
        }