Example #1
0
        public string CreateConsignment(string saediFromId, CreateConsignmentRequest createConsignmentRequest, out int shipmateConsignmentCreationId)
        {
            CreateConsignmentResponse     createConsignmentResponse;
            OnlineBookingLogBLL           onlineBookingLogBLL = new OnlineBookingLogBLL();
            ShipmateConsignmentDetailsBLL shipmateBLL         = new ShipmateConsignmentDetailsBLL();

            shipmateConsignmentCreationId = 0;
            string trackingReference = null;

            try
            {
                createConsignmentRequest.Token = _shipmateConfig.ShipmateToken;
                createConsignmentResponse      = MakeWebRequest <CreateConsignmentResponse>(GetUrl(ShipmateAction.CreateConsignment), createConsignmentRequest.ToJson());

                if (createConsignmentResponse.message == "Consignment Created")
                {
                    onlineBookingLogBLL.InsertOnlineServiceLog(createConsignmentRequest, createConsignmentResponse, saediFromId, GetUrl(ShipmateAction.CreateConsignment), true);
                    DateTime?labelCreated = GetLabelCreated(createConsignmentResponse.data[0].tracking_reference);
                    trackingReference             = createConsignmentResponse.data[0].tracking_reference;
                    shipmateConsignmentCreationId = shipmateBLL.CreateLogEntry(GetShipmateConsignmentDetails(true, null, createConsignmentRequest, createConsignmentResponse, labelCreated), true);
                }
                else
                {
                    onlineBookingLogBLL.InsertOnlineServiceLog(createConsignmentRequest, createConsignmentResponse.message + " " + StringHelper.Dump(createConsignmentResponse), saediFromId, GetUrl(ShipmateAction.CreateConsignment), false);
                    shipmateConsignmentCreationId = shipmateBLL.CreateLogEntry(GetShipmateConsignmentDetails(false, createConsignmentResponse.message, createConsignmentRequest, null, null), false);
                }
            }
            catch (Exception e)
            {
                onlineBookingLogBLL.InsertOnlineServiceLog(createConsignmentRequest, e.Message, saediFromId, GetUrl(ShipmateAction.CreateConsignment), false);
                shipmateBLL.CreateLogEntry(GetShipmateConsignmentDetails(false, e.Message, createConsignmentRequest, null, null), false);
                throw;
            }

            if (createConsignmentResponse.message != "Consignment Created")
            {
                throw new Exception(createConsignmentResponse.message);
            }

            return(trackingReference);
        }
Example #2
0
        private ShipmateConsignmentDetails GetShipmateConsignmentDetails(bool sendRequestSuccess, string errorMessage, CreateConsignmentRequest createConsignmentRequest, CreateConsignmentResponse createConsignmentResponse, DateTime?labelCreated)
        {
            ShipmateConsignmentDetails scd = new ShipmateConsignmentDetails();

            scd.ClientId                = _clientId;
            scd.SendRequestSuccess      = sendRequestSuccess;
            scd.SendRequestErrorMessage = errorMessage;

            if (sendRequestSuccess)
            {
                scd.ResTrackingReference = createConsignmentResponse.data[0].tracking_reference;
            }

            scd.LabelCreated                  = labelCreated;
            scd.ReqServiceID                  = createConsignmentRequest.ServiceID;
            scd.ReqRemittanceID               = createConsignmentRequest.RemittanceID;
            scd.ReqConsignmentReference       = createConsignmentRequest.consignment_reference;
            scd.ReqServiceKey                 = createConsignmentRequest.service_key;
            scd.ReqCollectionFromName         = createConsignmentRequest.collection_address.name;
            scd.ReqCollectionFromLine1        = createConsignmentRequest.collection_address.line_1;
            scd.ReqCollectionFromLine2        = createConsignmentRequest.collection_address.line_2;
            scd.ReqCollectionFromLine3        = createConsignmentRequest.collection_address.line_3;
            scd.ReqCollectionFromCompanyName  = createConsignmentRequest.collection_address.company_name;
            scd.ReqCollectionFromTelephone    = createConsignmentRequest.collection_address.telephone;
            scd.ReqCollectionFromEmailAddress = createConsignmentRequest.collection_address.email_address;
            scd.ReqCollectionFromCity         = createConsignmentRequest.collection_address.city;
            scd.ReqCollectionFromPostcode     = createConsignmentRequest.collection_address.postcode;
            scd.ReqCollectionFromCountry      = createConsignmentRequest.collection_address.country;
            scd.ReqDeliveryToName             = createConsignmentRequest.to_address.name;
            scd.ReqDeliveryToLine1            = createConsignmentRequest.to_address.line_1;
            scd.ReqDeliveryToLine2            = createConsignmentRequest.to_address.line_2;
            scd.ReqDeliveryToLine3            = createConsignmentRequest.to_address.line_3;
            scd.ReqDeliveryToCompanyName      = createConsignmentRequest.to_address.company_name;
            scd.ReqDeliveryToTelephone        = createConsignmentRequest.to_address.telephone;
            scd.ReqDeliveryToEmailAddress     = createConsignmentRequest.to_address.email_address;
            scd.ReqDeliveryToCity             = createConsignmentRequest.to_address.city;
            scd.ReqDeliveryToPostcode         = createConsignmentRequest.to_address.postcode;
            scd.ReqDeliveryToCountry          = createConsignmentRequest.to_address.country;
            scd.ReqParcelReference            = createConsignmentRequest.parcels[0].reference;
            scd.ReqParcelWeight               = createConsignmentRequest.parcels[0].weight;
            scd.ReqParcelWidth                = createConsignmentRequest.parcels[0].width;
            scd.ReqParcelLength               = createConsignmentRequest.parcels[0].length;
            scd.ReqParcelDepth                = createConsignmentRequest.parcels[0].depth;

            if (sendRequestSuccess)
            {
                scd.ResMessage = createConsignmentResponse.message;
                scd.ResConsignmentReference = createConsignmentResponse.data[0].consignment_reference;
                scd.ResParcelReference      = createConsignmentResponse.data[0].parcel_reference;
                scd.ResCarrier     = createConsignmentResponse.data[0].carrier;
                scd.ResServiceName = createConsignmentResponse.data[0].service_name;
                scd.ResCreatedBy   = createConsignmentResponse.data[0].created_by;
                scd.ResCreatedWith = createConsignmentResponse.data[0].created_with;
                scd.ResCreatedAt   = createConsignmentResponse.data[0].created_at;
                scd.ResMediaURL    = createConsignmentResponse.data[0].MediaURL;
                scd.ResMediaGUID   = createConsignmentResponse.data[0].MediaGUID;
            }

            return(scd);
        }