Exemple #1
0
        /// <summary>
        ///	Creates sales order in NetSuite
        /// </summary>
        /// <param name="order">Sales order</param>
        /// <param name="token">Cancellation token</param>
        /// <returns></returns>
        public async Task CreateSalesOrderAsync(NetSuiteSalesOrder order, string locationName, CancellationToken token, bool createCustomer = false)
        {
            var mark     = Mark.CreateNew();
            var location = await this.GetLocationByNameAsync(locationName, token).ConfigureAwait(false);

            if (location == null)
            {
                throw new NetSuiteException(string.Format("Location with name {0} is not found in NetSuite!", locationName));
            }

            var customer = await this._customersService.GetCustomerInfoByEmailAsync(order.Customer.Email, token).ConfigureAwait(false);

            if (customer == null)
            {
                if (!createCustomer)
                {
                    NetSuiteLogger.LogTrace(string.Format("Can't create sales order in NetSuite! Customer with email {0} was not found!", order.Customer.Email));
                    return;
                }

                if (string.IsNullOrWhiteSpace(order.Customer.FirstName) ||
                    string.IsNullOrWhiteSpace(order.Customer.LastName))
                {
                    NetSuiteLogger.LogTrace("Can't create sales order in NetSuite! Customer's first name or last name aren't specified!");
                    return;
                }

                customer = await this._soapService.CreateCustomerAsync(order.Customer, token, mark).ConfigureAwait(false);
            }

            await this._soapService.CreateSalesOrderAsync(order, location.Id, customer.Id, token, mark).ConfigureAwait(false);
        }
Exemple #2
0
        /// <summary>
        ///	Updates existing sales order in NetSuite
        /// </summary>
        /// <param name="order">Sales order</param>
        /// <param name="">Cancellation token</param>
        /// <returns></returns>
        public async Task UpdateSalesOrderAsync(NetSuiteSalesOrder order, string locationName, CancellationToken token)
        {
            var location = await this.GetLocationByNameAsync(locationName, token).ConfigureAwait(false);

            if (location == null)
            {
                throw new NetSuiteException(string.Format("Location with name {0} is not found in NetSuite!", locationName));
            }

            var customer = await this._customersService.GetCustomerInfoByEmailAsync(order.Customer.Email, token).ConfigureAwait(false);

            if (customer == null)
            {
                NetSuiteLogger.LogTrace(string.Format("Can't update sales order in NetSuite! Customer with email {0} was not found!", order.Customer.Email));
                return;
            }

            await this._soapService.UpdateSalesOrderAsync(order, location.Id, customer.Id, token).ConfigureAwait(false);
        }