public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentParcelHubIntegration(FrayteUploadshipment res)
        {
            FrayteResult      FR     = new FrayteResult();
            IntegrtaionResult result = new IntegrtaionResult();
            var count               = 0;
            int DirectShipmentid    = 0;
            var directBookingDetail = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            directBookingDetail.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);

            // Parcelhub Integration starts
            //Step 2: Shipment Integrations
            #region Parcel Hub Integration

            //Map Direct Booking object with parcel hub objects
            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapDirectBookingDetailToShipmentRequest(directBookingDetail);

            //Create shipment in Parcel hub
            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateShipment(request);

            if (response.Error.IsMailSend)
            {
                if (directBookingDetail.Error.IsMailSend)
                {
                    //Send error mail to developer
                    new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, response.Error);
                }
            }
            else
            {
                //Mapping ShipmentResonse to IntegrtaionResult
                result = new ParcelHubRepository().MappingParcelHubToIntegrationResult(directBookingDetail, response, null);

                if (result.Status)
                {
                    //Save Shipment Detail Into Our DB
                    DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, result);
                    if (DirectShipmentid > 0)
                    {
                        var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                    }
                    //Mapping ShipmentResult to IntegrtaionResult
                    new ParcelHubRepository().MappingCourierPieceDetail(result, directBookingDetail, DirectShipmentid);

                    //Save Package Label Tracking detail
                    new ParcelHubRepository().SaveTrackingDetail(directBookingDetail, result, DirectShipmentid);

                    //Start downloading the images from UPS server and making PDF
                    FratyteError Error = new ParcelHubRepository().DownloadParcelHubPackageImage(directBookingDetail, result, DirectShipmentid);
                }
                else
                {
                    if (result.Error.IsMailSend)
                    {
                        new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, res.CustomerId);
                        //Send error mail to developer
                        new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, directBookingDetail.Error);
                    }
                }
            }


            #endregion

            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
        }
Esempio n. 2
0
        public IHttpActionResult ExpressShipmentBooking(ExpressShipmentRequest Shipment)
        {
            try
            {
                List <FrayteUploadshipment> _upload = new ExpressShipmentRepository().JsonValidate(Shipment, FrayteCallingType.FrayteApi);
                if (_upload.Count > 0)
                {
                    return(Ok(_upload[0].Errors));
                }
                else
                {
                    var shipment = new ExpressShipmentRepository().MappingFrayteRequestToExpressBookingDetail(Shipment);
                    ExpressShipmentResponseModel ExpressResponse = new ExpressShipmentResponseModel();
                    ExpressShipmentModel         model           = new ExpressRepository().SaveShipment(shipment);
                    if (shipment.Error.Status && model.ShipmentStatusId == (int)FrayteExpressShipmentStatus.Scanned)
                    {
                        #region Logistic Integration
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                        {
                            #region DHL Integration
                            IntegrtaionResult result = new IntegrtaionResult();
                            //step 1. Mapping With express model to ShipmentRequestDto

                            var shipmentRequestDto = new DHLRepository().MapExpressShipmentToDHLShipmentRequestDto(shipment);

                            //Step 2. Create Xml
                            string shipmentXML = string.Empty;
                            //Version5.0

                            shipmentXML = new DHLRepository().CreateXMLForDHL(shipmentRequestDto);


                            //Version 6.2  not in use
                            // shipmentXML = new DHLUKRepositry().CreateXMLForDHLUK(shipmentRequestDto);
                            string xml_in = string.Empty;

                            xml_in = File.ReadAllText(@shipmentXML);

                            //step 3. Create Shipment
                            var DHLResponse = new DHLResponseDto();

                            DHLResponse = new DHLRepository().CreateShipment(xml_in, shipmentRequestDto);

                            //step 4. Mapping ShipmentResonse to IntegrtaionResult

                            result = new DHLRepository().MapDHLIntegrationResponse(DHLResponse);

                            if (result.Status)
                            {
                                if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                                {
                                    //Step 1.1 Mapping ShipmentResult to IntegrtaionResult
                                    try
                                    {
                                        new ExpressRepository().MappingCourierPieceDetail(result, shipment);
                                    }
                                    catch (Exception Ex)
                                    {
                                        throw (new FrayteApiException("MapDHLCourierPieceDetailError", Ex));
                                    }
                                }
                                //Step3 : Save Main Tracking Number
                                new ExpressRepository().SaveMainTrackingDetail(shipment, result, xml_in, "");
                                new ExpressRepository().SaveTrackingDetail(shipment, result);


                                // AfterShipIntegration

                                if (AppSettings.ApplicationMode == FrayteApplicationMode.Live)
                                {
                                    FrayteAfterShipTracking aftershipTracking = new AftershipTrackingRepository().MapDirectShipmentObjToAfterShip(shipment.ExpressId, FrayteShipmentServiceType.Express);

                                    if (aftershipTracking != null && AppSettings.ApplicationMode == FrayteApplicationMode.Live)
                                    {
                                        //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Integration in aftership"));
                                        new AftershipTrackingRepository().CreateTracking(aftershipTracking);
                                    }
                                }


                                //Step4:  //Start downloading the images from DHL server and making PDF
                                var count      = 1;
                                var totalpiece = result.PieceTrackingDetails.Count();
                                totalpiece = totalpiece - 1;

                                foreach (var data in result.PieceTrackingDetails.Take(totalpiece))
                                {
                                    if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                                    {
                                        // Step3.1
                                        data.LabelName = new DHLRepository().ExpressDownloadDHLImage(data, totalpiece, count, shipment.ExpressId);
                                    }
                                    if (!data.PieceTrackingNumber.Contains("AirwayBillNumber_"))
                                    {
                                        //Step3.2
                                        new ExpressRepository().SavePackageDetail(data, result.CourierName);
                                    }
                                    count++;
                                }
                                var CourierPieceDetail = result.PieceTrackingDetails.Where(t => t.PieceTrackingNumber.Contains("AirwayBillNumber_")).FirstOrDefault();
                                if (CourierPieceDetail != null)
                                {
                                    var data1 = new DHLRepository().ExpressDownloadDHLImage(CourierPieceDetail, totalpiece, 0, shipment.ExpressId);

                                    // save all dhl image
                                    new ExpressRepository().SaveLogisticLabelImage(shipment.ExpressId, data1);
                                }
                                if (result.Status)
                                {
                                    var status = Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);

                                    // Send Booking confirmation email
                                    if (status.Status)
                                    {
                                        ExpressEmailModel emailModel = new ExpressEmailModel();
                                        emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                        if (emailModel != null)
                                        {
                                            new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                        }
                                        new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                    }
                                }
                            }
                            else
                            {
                                shipment.Error = result.Error;
                            }
                            #endregion
                        }
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.Yodel)
                        {
                            #region Yodel Integration

                            //Map Direct Booking object with parcel hub objects
                            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapExpressBookingDetailToShipmentRequest(shipment);
                            //Create shipment in Parcel hub
                            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateShipment(request);
                            if (response.Error.IsMailSend)
                            {
                                //Send error mail to developer
                                shipment.Error               = new FratyteError();
                                shipment.Error.Custom        = new List <string>();
                                shipment.Error.Package       = new List <string>();
                                shipment.Error.Address       = new List <string>();
                                shipment.Error.Service       = new List <string>();
                                shipment.Error.ServiceError  = new List <string>();
                                shipment.Error.Miscellaneous = new List <string>();
                                shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                shipment.Error               = response.Error;

                                new DirectShipmentRepository().SaveExpressEasyPosyPickUpObject(Newtonsoft.Json.JsonConvert.SerializeObject(response.Error).ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(shipment).ToString(), shipment.ExpressId);
                            }
                            else
                            {
                                //Mapping ShipmentResonse to IntegrtaionResult
                                var result = new ParcelHubRepository().MappingExpressParcelHubToIntegrationResult(shipment, response, null);

                                if (result.Status)
                                {
                                    //Mapping ShipmentResult to IntegrtaionResult
                                    new ParcelHubRepository().MappingExpressCourierPieceDetail(result, shipment, shipment.ExpressId);

                                    //Save Package Label Tracking detail
                                    new ExpressRepository().SaveMainTrackingDetail(shipment, result, response.Request, response.Response);

                                    FratyteError Error = new ParcelHubRepository().DownloadExpressParcelHubPackageImage(shipment, result, shipment.ExpressId);

                                    //Start Making Final One pdf file for all package label
                                    Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);

                                    if (result.Status)
                                    {
                                        ExpressEmailModel emailModel = new ExpressEmailModel();
                                        emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                        if (emailModel != null)
                                        {
                                            new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                        }
                                        new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                    }
                                    shipment.Error = new FratyteError()
                                    {
                                        Status = result.Status,
                                    };
                                }
                                else
                                {
                                    if (result.Error.IsMailSend)
                                    {
                                        //Send error mail to developer
                                        shipment.Error               = new FratyteError();
                                        shipment.Error.Custom        = new List <string>();
                                        shipment.Error.Package       = new List <string>();
                                        shipment.Error.Address       = new List <string>();
                                        shipment.Error.Service       = new List <string>();
                                        shipment.Error.ServiceError  = new List <string>();
                                        shipment.Error.Miscellaneous = new List <string>();
                                        shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                        shipment.Error               = result.Error;
                                    }
                                }
                            }
                            #endregion
                        }
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.Hermes)
                        {
                            #region Hermes Integration

                            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapExpressBookingDetailToShipmentRequest(shipment);
                            //Create shipment in Parcel hub
                            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateHermesShipment(request);

                            if (response.Error.IsMailSend)
                            {
                                //Send error mail to developer
                                shipment.Error               = new FratyteError();
                                shipment.Error.Custom        = new List <string>();
                                shipment.Error.Package       = new List <string>();
                                shipment.Error.Address       = new List <string>();
                                shipment.Error.Service       = new List <string>();
                                shipment.Error.ServiceError  = new List <string>();
                                shipment.Error.Miscellaneous = new List <string>();
                                shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                shipment.Error               = response.Error;

                                new DirectShipmentRepository().SaveExpressEasyPosyPickUpObject(Newtonsoft.Json.JsonConvert.SerializeObject(response.Error).ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(shipment).ToString(), shipment.ExpressId);
                            }
                            else
                            {
                                //Mapping ShipmentResonse to IntegrtaionResult
                                var result = new ParcelHubRepository().MappingExpressParcelHubToIntegrationResult(shipment, response, null);

                                if (result.Status)
                                {
                                    //Mapping ShipmentResult to IntegrtaionResult
                                    new ParcelHubRepository().MappingExpressCourierPieceDetail(result, shipment, shipment.ExpressId);

                                    //Save Package Label Tracking detail
                                    new ExpressRepository().SaveMainTrackingDetail(shipment, result, response.Request, response.Response);

                                    //Start Making Final One pdf file for all package label
                                    Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);

                                    if (result.Status)
                                    {
                                        ExpressEmailModel emailModel = new ExpressEmailModel();
                                        emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                        if (emailModel != null)
                                        {
                                            new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                        }
                                        new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                    }
                                    shipment.Error = new FratyteError()
                                    {
                                        Status = result.Status,
                                    };
                                }
                                else
                                {
                                    if (result.Error.IsMailSend)
                                    {
                                        //Send error mail to developer
                                        shipment.Error               = new FratyteError();
                                        shipment.Error.Custom        = new List <string>();
                                        shipment.Error.Package       = new List <string>();
                                        shipment.Error.Address       = new List <string>();
                                        shipment.Error.Service       = new List <string>();
                                        shipment.Error.ServiceError  = new List <string>();
                                        shipment.Error.Miscellaneous = new List <string>();
                                        shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                        shipment.Error               = result.Error;
                                    }
                                }
                            }

                            #endregion
                        }
                        if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                        {
                            #region EAM Global Integration

                            IntegrtaionResult result = new IntegrtaionResult();
                            if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                            {
                                var    shipmentRequestDto = new EAMGlobalRepository().MapExpressBookingDetailToShipmentRequestDto(shipment);
                                string shipmentXML        = new EAMGlobalRepository().CreateXMLForEAM(shipmentRequestDto);
                                string xml_in             = File.ReadAllText(@shipmentXML);

                                //Create Shipment
                                var shipmentResult = new EAMGlobalRepository().CreateShipment(xml_in, shipment.ExpressId);
                                result = new EAMGlobalRepository().MapExpressEAMGlobalIntegrationResponse(shipmentResult, shipment.Packages);
                            }

                            if (result.Status)
                            {
                                if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                                {
                                    //Mapping ShipmentResult to IntegrtaionResult
                                    new ExpressRepository().MappingCourierPieceDetail(result, shipment);
                                }

                                //Save Package Label Tracking detail
                                new ExpressRepository().SaveMainTrackingDetail(shipment, result, "", "");

                                //Start downloading the images from DPD server and making PDF
                                var count = 1;
                                foreach (var data in result.PieceTrackingDetails)
                                {
                                    if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                                    {
                                        //Step3.1
                                        data.LabelName = new EAMGlobalRepository().DownloadExpressEAMImageTOPDF(data, result.PieceTrackingDetails.Count(), count, shipment.ExpressId, shipment.Service);
                                    }
                                    // Step3.2
                                    new ExpressRepository().SavePackageDetail(data, result.CourierName);
                                    count++;
                                }
                                //Step:4 Generate PDF
                                Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);
                                if (result.Status)
                                {
                                    ExpressEmailModel emailModel = new ExpressEmailModel();
                                    emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                    if (emailModel != null)
                                    {
                                        new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                    }
                                    new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                }

                                shipment.Error = new FratyteError()
                                {
                                    Status = result.Status,
                                };
                            }
                            else
                            {
                                shipment.Error = result.Error;
                            }

                            #endregion
                        }

                        #endregion

                        return(Ok(ExpressResponse));
                    }
                }
            }
            catch (Exception Ex)
            {
                string error = ReadException(Ex);
                ExpressErrorResponse Response = new FrayteApiErrorCodeRepository().SaveExpressApiError(error);
                return(Ok(Response));
            }
            return(Ok());
        }