Пример #1
0
        public static NavSalesOrder UpdateSalesOrderForNAV(ActiveUser activeUser, NavSalesOrderRequest navSalesOrder, string navAPIUrl, string navAPIUserName, string navAPIPassword, string soNumber)
        {
            NavSalesOrder navSalesOrderResponse = null;
            string        navSalesOrderJson     = string.Empty;
            string        proFlag = null;

            Newtonsoft.Json.Linq.JObject jsonObject = null;
            string serviceCall = string.Format("{0}/SalesOrder('Order', '{1}')", navAPIUrl, soNumber);

            try
            {
                NavSalesOrder     existingSalesOrderData = GetSalesOrderForNAV(navAPIUrl, navAPIUserName, navAPIPassword, soNumber);
                NetworkCredential myCredentials          = new NetworkCredential(navAPIUserName, navAPIPassword);
                HttpWebRequest    request = (HttpWebRequest)WebRequest.Create(serviceCall);
                request.Credentials             = myCredentials;
                request.KeepAlive               = false;
                request.ContentType             = "application/json";
                request.Method                  = "PATCH";
                existingSalesOrderData.DataETag = existingSalesOrderData.DataETag.Replace("W/", string.Empty);
                request.Headers.Add(HttpRequestHeader.IfMatch, existingSalesOrderData.DataETag);
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    navSalesOrderJson = JsonConvert.SerializeObject(navSalesOrder);
                    jsonObject        = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(navSalesOrderJson);
                    jsonObject.Property("Ship_from_City").Remove();
                    jsonObject.Property("Ship_from_County").Remove();
                    navSalesOrderJson = jsonObject.ToString();
                    streamWriter.Write(navSalesOrderJson);
                }

                WebResponse response = request.GetResponse();

                using (Stream navSalesOrderResponseStream = response.GetResponseStream())
                {
                    using (TextReader navSalesOrderReader = new StreamReader(navSalesOrderResponseStream))
                    {
                        string navSalesOrderResponseString = navSalesOrderReader.ReadToEnd();

                        using (var stringReader = new StringReader(navSalesOrderResponseString))
                        {
                            navSalesOrderResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <NavSalesOrder>(navSalesOrderResponseString);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                proFlag = Entities.ProFlag.H.ToString();
                _logger.Log(exp, string.Format("Error is occuring while Updating the Sales order: Request Url is: {0}, Request body json was {1}", serviceCall, navSalesOrderJson), string.Format("Sales order updation for JobId: {0}", navSalesOrder.M4PL_Job_ID), LogType.Error);
            }

            var jobIdList = new System.Collections.Generic.List <long>();

            jobIdList.Add(Convert.ToInt64(navSalesOrder.M4PL_Job_ID));
            _commands.UpdateJobProFlag(activeUser, proFlag, jobIdList, Entities.EntitiesAlias.SalesOrder);

            return(navSalesOrderResponse);
        }
Пример #2
0
        public static NavSalesOrder StartOrderUpdationProcessForNAV(ActiveUser activeUser, List <long> jobIdList, string soNumber, string poNumber, string navAPIUrl, string navAPIUserName, string navAPIPassword, string vendorNo, bool electronicInvoice, List <SalesOrderItem> salesOrderItemRequest)
        {
            string dimensionCode       = string.Empty;
            string divisionCode        = string.Empty;
            bool   allLineItemsUpdated = true;
            string proFlag             = null;
            NavSalesOrderRequest navSalesOrderRequest = _commands.GetSalesOrderCreationData(activeUser, jobIdList, Entities.EntitiesAlias.SalesOrder);

            if (navSalesOrderRequest == null)
            {
                return(null);
            }
            var dimensions = CommonCommands.GetSalesOrderDimensionValues(navAPIUserName, navAPIPassword, navAPIUrl);

            if (dimensions != null && dimensions.NavSalesOrderDimensionValues != null && dimensions.NavSalesOrderDimensionValues.Count > 0)
            {
                divisionCode = dimensions.NavSalesOrderDimensionValues.Where(x => !string.IsNullOrEmpty(x.Dimension_Code) && x.Dimension_Code.ToUpper() == "DIVISION" && x.ERPId == navSalesOrderRequest.Sell_to_Customer_No).Any()
                                        ? dimensions.NavSalesOrderDimensionValues.Where(x => !string.IsNullOrEmpty(x.Dimension_Code) && x.Dimension_Code.ToUpper() == "DIVISION" && x.ERPId == navSalesOrderRequest.Sell_to_Customer_No).FirstOrDefault().Code
                                        : string.Empty;

                if (!string.IsNullOrEmpty(navSalesOrderRequest.Ship_from_City) && !string.IsNullOrEmpty(navSalesOrderRequest.Ship_from_County))
                {
                    string dimensionMatchCode = navSalesOrderRequest.Ship_from_City.Length >= 3 ? string.Format("{0}{1}", navSalesOrderRequest.Ship_from_City.Substring(0, 3), navSalesOrderRequest.Ship_from_County) : string.Empty;
                    if (!string.IsNullOrEmpty(dimensionMatchCode))
                    {
                        dimensionCode = dimensions.NavSalesOrderDimensionValues.Where(codeMatch => !string.IsNullOrEmpty(codeMatch.Code) && codeMatch.Code.Length > 4 && codeMatch.Code.Substring(codeMatch.Code.Length - 5).ToUpper() == dimensionMatchCode.ToUpper()).Any() ?
                                        dimensions.NavSalesOrderDimensionValues.Where(codeMatch => !string.IsNullOrEmpty(codeMatch.Code) && codeMatch.Code.Length > 4 && codeMatch.Code.Substring(codeMatch.Code.Length - 5).ToUpper() == dimensionMatchCode.ToUpper()).FirstOrDefault().Code : dimensionCode;
                    }
                }
            }

            navSalesOrderRequest.Shortcut_Dimension_2_Code = dimensionCode;
            navSalesOrderRequest.Shortcut_Dimension_1_Code = divisionCode;
            navSalesOrderRequest.Electronic_Invoice        = electronicInvoice;
            NavSalesOrder navSalesOrderResponse = UpdateSalesOrderForNAV(activeUser, navSalesOrderRequest, navAPIUrl, navAPIUserName, navAPIPassword, soNumber);

            if (navSalesOrderResponse != null && !string.IsNullOrWhiteSpace(navSalesOrderResponse.No))
            {
                salesOrderItemRequest.ForEach(x => x.Document_No = navSalesOrderResponse.No);
                //Task.Run(() =>
                //{
                UpdateSalesOrderItemDetails(activeUser, jobIdList, navAPIUrl, navAPIUserName, navAPIPassword, dimensionCode, divisionCode, navSalesOrderResponse.No, ref allLineItemsUpdated, ref proFlag, electronicInvoice, salesOrderItemRequest);
                //});
            }

            return(navSalesOrderResponse);
        }