예제 #1
0
        public DPDRequestModel MapExpressBookingDetailToShipmentRequestDto(ExpressShipmentModel shipment)
        {
            try
            {
                //ShipFromAddress
                var collectionDetails = new CollectionDetails();
                mapCallectionAddressDetail(shipment, collectionDetails);

                //ShipToAddress
                var deliveryDetails = new DeliveryDetails();
                mapDeliveryAddressDetail(shipment, deliveryDetails);


                DPDRequestModel dpdShipmentRequest = new DPDRequestModel();
                dpdShipmentRequest.DraftShipmentId      = shipment.ExpressId;
                dpdShipmentRequest.collectionDate       = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss");
                dpdShipmentRequest.collectionOnDelivery = false;
                dpdShipmentRequest.invoice     = null;
                dpdShipmentRequest.consolidate = false;
                dpdShipmentRequest.job_id      = null;
                dpdShipmentRequest.consignment = new List <Consignment>();
                int TotalNumberParcel = 0;
                foreach (var item in shipment.Packages)
                {
                    TotalNumberParcel += item.CartonValue;
                }
                dpdShipmentRequest.consignment.Add(new Consignment
                {
                    consignmentNumber    = null,
                    consignmentRef       = null,
                    parcels              = new List <Parcels>(),
                    collectionDetails    = collectionDetails,
                    deliveryDetails      = deliveryDetails,
                    networkCode          = shipment.Service.NetworkCode,
                    numberOfParcels      = TotalNumberParcel,
                    totalWeight          = shipment.Service.ActualWeight,
                    customsValue         = null,
                    deliveryInstructions = "Please deliver with shipment owner",
                    liability            = false,
                    liabilityValue       = null,
                    parcelDescription    = string.Join("-", shipment.Packages.Select(x => x.Content.ToString()).ToArray()),
                    shippingRef1         = shipment.FrayteNumber + "-" + shipment.ShipmentReference,
                    shippingRef2         = "",
                    shippingRef3         = "",
                });


                return(dpdShipmentRequest);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Shipment is not created " + ex.Message));
                return(null);
            }
        }
예제 #2
0
        public DpdShipmentResponse CreateShipment(DPDRequestModel dpdRequestObj)
        {
            DpdShipmentResponse respone = new DpdShipmentResponse();
            var    logisticIntegration  = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.DPD);
            string result = string.Empty;

            var abc = Newtonsoft.Json.JsonConvert.SerializeObject(dpdRequestObj);

            #region DPD API Login

            string usernamePasswordBase64String = Base64Encode(logisticIntegration.UserName + ":" + logisticIntegration.Password);
            //Api Login
            string loginRespone = LogindpdWebApi(logisticIntegration, usernamePasswordBase64String);
            var    DPDLogin     = Newtonsoft.Json.JsonConvert.DeserializeObject <DPDLoginResponeModel>(loginRespone);
            if (DPDLogin.error == null)
            {
                var shipmentRequestjson = JsonConvert.SerializeObject(dpdRequestObj);
                //Insert Shipment
                string shipmentResponsejson = CallDpdWebApi(logisticIntegration, shipmentRequestjson, DPDLogin.data.geoSession);

                respone.DPDResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <DPDResponseModel>(shipmentResponsejson);
                if (respone.DPDResponse.error == null)
                {
                    //Get Label
                    respone.LabelHTMLString = CallDpdLabelApi(logisticIntegration, respone.DPDResponse.data.shipmentId, DPDLogin.data.geoSession, "text/html");
                    respone.LabeleplString  = CallDpdLabelApi(logisticIntegration, respone.DPDResponse.data.shipmentId, DPDLogin.data.geoSession, "text/vnd.eltron-epl");
                    //Collection Pickup

                    return(respone);
                }
                else
                {
                    respone.Error         = new FratyteError();
                    respone.Error.Service = new List <string>();
                    string err = string.Empty;
                    foreach (var error in respone.DPDResponse.error)
                    {
                        err += error.Obj + " - " + error.errorMessage + ",";
                    }

                    respone.Error.Service.Add(err);

                    respone.Error.Status = false;
                    //Error Recorded
                    SaveDirectShipmentObject(shipmentRequestjson, respone.DPDResponse.error.ToString(), dpdRequestObj.DraftShipmentId);
                }
            }
            else
            {
                respone.Error         = new FratyteError();
                respone.Error.Service = new List <string>();
                string err = string.Empty;
                foreach (var error in respone.DPDResponse.error)
                {
                    err += error.Obj + " - " + error.errorMessage + ",";
                }
                respone.Error.Service.Add(err);

                respone.Error.Status = false;
                //Error Recorded
                SaveDirectShipmentObject(usernamePasswordBase64String, respone.DPDResponse.error.ToString(), dpdRequestObj.DraftShipmentId);
            }
            #endregion

            return(respone);
        }