コード例 #1
0
        /// <summary>
        /// get customer address by address code
        /// </summary>
        /// <param name="addressCode"></param>
        /// <returns></returns>
        public RM00102_CustomerAddress GetCustomerAddress(string addressCode)
        {
            var address = new RM00102_CustomerAddress();

            try
            {
                address = _dynamicsContext.RM00102_CustomerAddress.FirstOrDefault(x => x.ADRSCODE.Replace(" ", string.Empty).ToLower() == addressCode.Replace(" ", string.Empty).ToLower());
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting customer address: {0} ", ex.ToString());
            }

            return(address);
        }
コード例 #2
0
        /// <summary>
        /// convert customer address to customer view model
        /// </summary>
        /// <param name="customerAddress"></param>
        /// <returns></returns>
        public CustomerViewModel ConvertToView(RM00102_CustomerAddress customerAddress)
        {
            CustomerViewModel model = new CustomerViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _stateRepository            = new StateRepository();
            var _countryRepository          = new CountryRepository();
            var _siteDynamicsRepository     = new SiteDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(customerAddress.CUSTNMBR);
            var state            = _stateRepository.GetState(customerAddress.STATE);
            var country          = _countryRepository.GetCountry(customerAddress.COUNTRY);
            var dynamicsSite     = _siteDynamicsRepository.GetSite(customerAddress.LOCNCODE);

            var type = (dynamicsCustomer != null && customerAddress.ADRSCODE.Replace(" ", string.Empty).Equals(dynamicsCustomer.PRBTADCD.Replace(" ", string.Empty))) ?
                       "Bill To Address" : (dynamicsCustomer != null && customerAddress.ADRSCODE.Replace(" ", string.Empty).Equals(dynamicsCustomer.PRSTADCD.Replace(" ", string.Empty))) ?
                       "Ship To Address" : (dynamicsCustomer != null && customerAddress.ADRSCODE.Replace(" ", string.Empty).Equals(dynamicsCustomer.STADDRCD.Replace(" ", string.Empty))) ?
                       "Standard Address" : "N/A";

            model.CustomerAddressId = customerAddress.ADRSCODE;
            model.CustomerNumber    = customerAddress.CUSTNMBR;
            model.ShortName         = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.AddressCode       = customerAddress.ADRSCODE;
            model.AddressType       = type;
            model.ContactName       = (!string.IsNullOrEmpty(customerAddress.CNTCPRSN.Replace(" ", string.Empty))) ? customerAddress.CNTCPRSN : "N/A";
            model.ContactPhone      = FormattingManager.FormatPhone(customerAddress.PHONE1);
            model.FaxNumber         = FormattingManager.FormatPhone(customerAddress.FAX);
            model.Address1          = (!string.IsNullOrEmpty(customerAddress.ADDRESS1.Replace(" ", string.Empty))) ? customerAddress.ADDRESS1 : "N/A";
            model.Address2          = (!string.IsNullOrEmpty(customerAddress.ADDRESS2.Replace(" ", string.Empty))) ? customerAddress.ADDRESS2 : "N/A";
            model.Address3          = (!string.IsNullOrEmpty(customerAddress.ADDRESS3.Replace(" ", string.Empty))) ? customerAddress.ADDRESS3 : "N/A";
            model.City            = (!string.IsNullOrEmpty(customerAddress.CITY.Replace(" ", string.Empty))) ? customerAddress.CITY : "N/A";
            model.StateName       = (state != null && !string.IsNullOrEmpty(state.Name)) ? state.Name : "N/A";
            model.PostalCode      = (!string.IsNullOrEmpty(customerAddress.ZIP.Replace(" ", string.Empty))) ? customerAddress.ZIP : "N/A";
            model.CountryName     = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A";
            model.ShippingMethod  = (!string.IsNullOrEmpty(customerAddress.SHIPMTHD.Replace(" ", string.Empty))) ? customerAddress.SHIPMTHD : "N/A";
            model.SiteDescription = (dynamicsSite != null && !string.IsNullOrEmpty(dynamicsSite.LOCNDSCR.Replace(" ", string.Empty))) ? dynamicsSite.LOCNDSCR : "N/A";

            if (_customerDynamicsRepository != null)
            {
                _customerDynamicsRepository.Dispose();
                _customerDynamicsRepository = null;
            }

            if (_stateRepository != null)
            {
                _stateRepository.Dispose();
                _stateRepository = null;
            }

            if (_countryRepository != null)
            {
                _countryRepository.Dispose();
                _countryRepository = null;
            }

            if (_siteDynamicsRepository != null)
            {
                _siteDynamicsRepository.Dispose();
                _siteDynamicsRepository = null;
            }

            return(model);
        }
コード例 #3
0
        /// <summary>
        /// save customer address
        /// </summary>
        /// <param name="newAddress"></param>
        /// <returns></returns>
        public OperationResult SaveCustomerAddress(RM00102_CustomerAddress newAddress)
        {
            var operationResult = new OperationResult();

            var existingAddress = _dynamicsContext.RM00102_CustomerAddress.FirstOrDefault(x => x.ADDRESS1.ToLower() == newAddress.ADDRESS1.ToLower());

            if (existingAddress == null)
            {
                logger.Debug("Customer Address is being created...");

                string sCustomerDocument;
                string sXsdSchema;
                string sConnectionString;

                using (eConnectMethods e = new eConnectMethods())
                {
                    try
                    {
                        //// Create the vendor data file
                        //SerializeVendorObject("Vendor.xml", foundry);

                        //// Use an XML document to create a string representation of the customer
                        //XmlDocument xmldoc = new XmlDocument();
                        //xmldoc.Load("Vendor.xml");
                        //sCustomerDocument = xmldoc.OuterXml;

                        //// Specify the Microsoft Dynamics GP server and database in the connection string
                        //sConnectionString = @"data source=localhost;initial catalog=TWO;integrated security=SSPI;persist security info=False;packet size=4096";

                        //// Create an XML Document object for the schema
                        //XmlDocument XsdDoc = new XmlDocument();

                        //// Create a string representing the eConnect schema
                        //sXsdSchema = XsdDoc.OuterXml;

                        //// Pass in xsdSchema to validate against.
                        //e.CreateEntity(sConnectionString, sCustomerDocument);

                        // Instantiate a taCreateCustomerAddress_ItemsTaCreateCustomerAddress XML node object
                        taCreateCustomerAddress_ItemsTaCreateCustomerAddress address = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress();

                        //Populate elements of the taCreateCustomerAddress_ItemsTaCreateCustomerAddress XML node object
                        address.ADRSCODE       = newAddress.ADRSCODE;
                        address.CUSTNMBR       = newAddress.CUSTNMBR;
                        address.UpdateIfExists = 0;

                        // Instantiate a RMCustomerAddressType schema object
                        RMCustomerAddressType addresstype = new RMCustomerAddressType();

                        // Populate the RMCustomerAddressType schema with the taCreateCustomerAddress_Items XML node
                        addresstype.taCreateCustomerAddress_Items = new taCreateCustomerAddress_ItemsTaCreateCustomerAddress[1] {
                            address
                        };
                        RMCustomerAddressType[] customerAddress = { addresstype };

                        // 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 RMCustomerAddressType schema object
                        eConnect.RMCustomerAddressType = customerAddress;

                        // 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 customer address: {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 customer address: {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);
        }