Пример #1
0
        public BringResponseModel CreateShipment(BringRequestModel bringRequest, int DraftShipmentId, string ShipmentType)
        {
            BringResponseModel response = new BringResponseModel();
            var logisticIntegration     = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.BRING);
            //API Login
            var    shipmentRequestjson = JsonConvert.SerializeObject(bringRequest);
            string result = string.Empty;

            try
            {
                result = CallBringApi(logisticIntegration, shipmentRequestjson);

                if (!string.IsNullOrWhiteSpace(result))
                {
                    response = Newtonsoft.Json.JsonConvert.DeserializeObject <BringResponseModel>(result);
                }
                else
                {
                    var error = new Models.Bring.Error();
                    error.code      = "There is something is error please contact to admin";
                    response.errors = new List <Models.Bring.Error>();
                    response.errors.Add(error);
                    if (ShipmentType == FrayteShipmentServiceType.DirectBooking)
                    {
                        new DirectShipmentRepository().SaveEasyPostErrorObject("Bring-result:-" + @result, "Bring-ShipJSON:-" + shipmentRequestjson, DraftShipmentId);
                    }
                }
                response.request  = shipmentRequestjson;
                response.response = result;
            }
            catch (Exception ex)
            {
                var error = new Models.Bring.Error();
                error.code = ex.InnerException.ToString();
                response.errors.Add(error);
                if (ShipmentType == FrayteShipmentServiceType.DirectBooking)
                {
                    new DirectShipmentRepository().SaveEasyPostErrorObject("Bring-result:-" + @result, "Bring-ShipJSON:-" + shipmentRequestjson, DraftShipmentId);
                }
            }
            return(response);
        }
Пример #2
0
        public BringRequestModel MapDirectBookingDetailToShipmentRequestDto(DirectBookingShipmentDraftDetail directBookingDetail)
        {
            BringRequestModel bringRequest = new BringRequestModel();

            if (AppSettings.ApplicationMode == FrayteApplicationMode.Test)
            {
                bringRequest.testIndicator = true;
            }
            else
            {
                bringRequest.testIndicator = false;
            }

            bringRequest.schemaVersion = 1;
            bringRequest.consignments  = new List <ConsignmentModel>();
            var packages = new List <Models.Bring.Package>();

            Models.Bring.Package package = new Models.Bring.Package();
            for (int i = 0; i < directBookingDetail.Packages.Count; i++)
            {
                for (int j = 0; j < directBookingDetail.Packages[i].CartoonValue; j++)
                {
                    package.weightInKg       = directBookingDetail.Packages[i].Weight.ToString("0.##");
                    package.goodsDescription = directBookingDetail.Packages[i].Content;
                    package.dimensions       = new Dimensions()
                    {
                        heightInCm = directBookingDetail.Packages[i].Height,
                        lengthInCm = directBookingDetail.Packages[i].Length,
                        widthInCm  = directBookingDetail.Packages[i].Width,
                    };
                    package.containerId   = directBookingDetail.FrayteNumber;
                    package.packageType   = "";
                    package.numberOfItems = "";
                    package.correlationId = "PACKAGE-" + directBookingDetail.FrayteNumber;
                    packages.Add(package);
                }
            }

            var ShipFrom             = new ExpressRepository().getHubAddress(directBookingDetail.ShipTo.Country.CountryId, directBookingDetail.ShipTo.PostCode, directBookingDetail.ShipTo.State);
            ConsignmentModel consign = new ConsignmentModel()
            {
                shippingDateTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ss"),

                parties = new Parties()
                {
                    sender = new Sender()
                    {
                        //name = string.IsNullOrWhiteSpace(ShipFrom.CompanyName) ? ShipFrom.FirstName + " " + ShipFrom.LastName : ShipFrom.CompanyName,
                        //addressLine = ShipFrom.Address,
                        //addressLine2 = ShipFrom.Address2,
                        //additionalAddressInfo = "",
                        //postalCode = ShipFrom.PostCode,
                        //city = ShipFrom.City,
                        //countryCode = ShipFrom.Country.Code2,
                        //reference = directBookingDetail.FrayteNumber + "-" + directBookingDetail.ReferenceDetail.Reference1,
                        //contact = new Contact
                        //{
                        //    name = string.IsNullOrEmpty(ShipFrom.FirstName + " " + ShipFrom.LastName) ? ShipFrom.CompanyName : ShipFrom.FirstName + " " + ShipFrom.LastName,
                        //    email = string.IsNullOrEmpty(ShipFrom.Email) ? "*****@*****.**" : ShipFrom.Email,
                        //    phoneNumber = ShipFrom.Phone
                        //}

                        name                  = "Priority Cargo AS",
                        addressLine           = "Skur 97,Kongshavnveien 29,",
                        addressLine2          = "Kongshavnveien 29,",
                        additionalAddressInfo = "",
                        postalCode            = "0193",
                        city                  = "Oslo",
                        countryCode           = "NO",
                        reference             = directBookingDetail.FrayteNumber + "-" + directBookingDetail.ReferenceDetail.Reference1,
                        contact               = new Contact
                        {
                            name        = "Priority Cargo AS",
                            email       = "*****@*****.**",
                            phoneNumber = "+47 9760 0402"
                        }
                    },
                    recipient = new Recipient()
                    {
                        name                  = string.IsNullOrWhiteSpace(directBookingDetail.ShipTo.CompanyName) ? directBookingDetail.ShipTo.FirstName + " " + directBookingDetail.ShipTo.LastName : directBookingDetail.ShipTo.CompanyName,
                        addressLine           = directBookingDetail.ShipTo.Address,
                        addressLine2          = directBookingDetail.ShipTo.Address2,
                        additionalAddressInfo = "",
                        postalCode            = directBookingDetail.ShipTo.PostCode,
                        city                  = directBookingDetail.ShipTo.City,
                        countryCode           = directBookingDetail.ShipTo.Country.Code2,
                        //reference = directBookingDetail.FrayteNumber + "-" + directBookingDetail.ReferenceDetail.Reference1,
                        reference = directBookingDetail.FrayteNumber + "-" + directBookingDetail.ReferenceDetail.Reference1,
                        contact   = new Contact
                        {
                            name        = directBookingDetail.ShipTo.FirstName + " " + directBookingDetail.ShipTo.LastName,
                            email       = string.IsNullOrEmpty(directBookingDetail.ShipTo.Email) ? "*****@*****.**" : directBookingDetail.ShipTo.Email,
                            phoneNumber = directBookingDetail.ShipTo.Phone
                        }
                    },
                    pickupPoint = null
                },
                product = new Product()
                {
                    id                 = "PA_DOREN",
                    customerNumber     = directBookingDetail.CustomerRateCard.NetworkCode,
                    services           = null,
                    customsDeclaration = directBookingDetail.CustomInfo.CatagoryOfItemExplanation,
                },
                purchaseOrder = null,
                correlationId = null,
                packages      = packages
            };

            bringRequest.consignments.Add(consign);
            GetXMLFromRequestObject(bringRequest);
            return(bringRequest);
        }