コード例 #1
0
        public ServiceResponse PostOrderToMapicsAsync(ERPOrderInfo orderArray)
        {
            if (orderArray == null)
            {
                return(Response);
            }

            var httpClient = SetUpHeadersAndAuthentication();

            using (httpClient)
            {
                try
                {
                    var url             = Utilities.Config("PostOrdersUrl");
                    var httpResponseMsg = httpClient.PostAsJsonAsync(url, orderArray).Result;

                    using (var responseHelper = new HttpResponseHelper(httpResponseMsg))
                    {
                        Response = httpResponseMsg.IsSuccessStatusCode ? responseHelper.GetPostOrdersApiResponse()
                                            : responseHelper.GetAppropriateResponseMessage(http_failure_post_order);
                    }
                }
                catch (Exception ex)
                {
                    Response.Messages.AddError(ex.Message);
                    return(Response);
                }
            }

            return(Response);
        }
コード例 #2
0
        public ERPOrderInfo CheckStatusForInProcessOrdersAsync(string orderNumber)
        {
            var orderInfo = new ERPOrderInfo();

            var httpClient = SetUpHeadersAndAuthentication();

            using (httpClient)
            {
                try
                {
                    var url             = Utilities.Config("CheckInProcessOrdersStatus");
                    var httpResponseMsg = httpClient.GetAsync(url).Result;

                    using (var responseHelper = new HttpResponseHelper(httpResponseMsg))
                    {
                        orderInfo = httpResponseMsg.IsSuccessStatusCode
                                    ? responseHelper.GetInProcessOrderStatus()
                                    : null;
                    }
                }
                catch (Exception ex)
                {
                    orderInfo = null;
                }
            }

            return(orderInfo);
        }
コード例 #3
0
        public ServiceResponse CheckWithMapicsBeforeSavingToDb(List <OrderItemsViewModel> orderItemsVm, Order order,
                                                               OrderViewModelLight model)
        {
            var orderDetailList = new List <OrderDetail>(); // array of order detail to send it to mapics
            var address         = Db.Addresses.FirstOrDefault(x => x.AddressId == model.ShipToAddressId);
            var state           = Db.States.FirstOrDefault(x => x.StateId == address.StateId);

            var increment = 1;

            foreach (var item in orderItemsVm)
            {
                var orderDetail = new OrderDetail()
                {
                    LineSeq            = increment,
                    ProductNumber      = item.ProductNumber,
                    CustomerProductNo  = "",
                    Quantity           = item.Quantity,
                    NetPrice           = item.NetPrice,
                    ExtendedNetPrice   = item.ExtendedPrice,
                    ProductDescription = "",
                    DiscountPercent    = item.DiscountPercentage,
                    CompanyNo          = 1,
                };
                increment++;

                orderDetailList.Add(orderDetail);
            }

            //construct json array to post it to mapics
            var jsonData = new ERPOrderInfo
            {
                CustomerNumber    = !string.IsNullOrWhiteSpace(model.ERPAccountId) ? Convert.ToInt32(model.ERPAccountId) : 0,
                PONo              = model.PONumber,
                PODate            = DateTime.Today,
                RequestDate       = model.OrderReleaseDate,
                TermsCode         = "",
                OrderType         = "DK",
                ShipToName        = model.ShipToName,
                ShipToAddress1    = address?.AddressLine1,
                ShipToAddress2    = address?.AddressLine2,
                ShipToCity        = address?.Location,
                ShipToState       = state?.Code,
                ShipToZip         = address?.PostalCode,
                ShipToInstruction = order.Comments,  ///From Delivery notes
                ContactName       = model.DeliveryContactName,
                ContactPhone      = model.DeliveryContactPhone,
                TotalAmount       = model.TotalNetPrice,
                OrderCode         = "DK",
                Status            = model.ERPStatus,
                ShipToNumber      = null,
                CompanyNo         = 1,
                BusinessID        = model.BusinessId.GetValueOrDefault(),
                BusinessName      = model.BusinessName,
                ProjectID         = model.ProjectId,
                ProjectName       = model.ProjectName,
                ProjectRefID      = null,
                QuoteID           = model.QuoteId,
                QuoteRefID        = null,
                Comments          = model.Comments,
                DiscountPercent   = 0,
                Details           = orderDetailList?.ToArray()
            };

            using (var erpClient = new ERPClient())
            {
                this.Response = erpClient.PostOrderToMapicsAsync(jsonData);
            }

            return(this.Response);
        }