Exemple #1
0
        /// <summary>
        /// Inserts the order to database.
        /// </summary>
        /// <param name="webOrder">The web order.</param>
        private void InsertOrderToDB(WebOrderHeaderModel webOrder)
        {
            OrderDataService OrderDataServ = null;

            try
            {
                OrderDataServ = HttpContext.Current.Application["OrderDataServ"] as OrderDataService;
                OrderDataServ.IncrementPFDWebOrderID(); // Increment before fetch
                webOrder.WebId        = OrderDataServ.GetNextPFDWebOrderId();
                webOrder.CustomerCode = OrderDataServ.GetCustomerCodeById(webOrder.BillTo);

                string ackCustCode = OrderDataServ.GetAckCustCode(webOrder.CustomerCode);

                if (!string.IsNullOrEmpty(ackCustCode))
                {
                    webOrder.IsAckRequired = 1;
                }
                else
                {
                    webOrder.IsAckRequired = 0;
                }

                if (string.IsNullOrEmpty(webOrder.CustomerCode) == false)
                {
                    webOrder.OrderNote = " ";
                }
            }
            catch (QueryExecutionException ex)
            {
                Log.Error($"Query execution exception {ex.Message}");
                throw;
            }

            webOrder.Comments = " ";

            bool success = false;

            try
            {
                success = OrderDataServ.InsertWebOrderHeader(webOrder);
            }
            catch (QueryExecutionException ex)
            {
                Log.Error($"Order header insertion failed. {ex.Message} + Inner Ex : {ex.InnerException.Message}");
                throw;
            }

            if (false == success)
            {
                return;
            }


            foreach (WebOrderDetailModel wod in webOrder.WebOrderDetailList)
            {
                try
                {
                    wod.WebId = webOrder.WebId;

                    if (string.IsNullOrEmpty(wod.CatlogCode))
                    {
                        wod.CatlogCode  = OrderDataServ.GetCatlogCodeByGTIN(wod.GTINCode);
                        wod.ProductNote = wod.CatlogCode;
                    }
                    success = OrderDataServ.InsertWebOrderDetail(wod);
                }
                catch (QueryExecutionException ex)
                {
                    Log.Error($"Order detail insertion failed. {ex.Message} + Inner Ex : {ex.InnerException.Message}, rolling back.");
                    OrderDataServ.RollBackOrderReferences(webOrder.WebId);
                    throw;
                }
                if (success == false)
                {
                    Log.Error($"Order detail inserttion failed for web order id : {webOrder.WebId} , rolling back.");
                    OrderDataServ.RollBackOrderReferences(webOrder.WebId);
                    return;
                }
            }
        }