コード例 #1
0
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentDHLIntegration(FrayteUploadshipment res)
        {
            IntegrtaionResult result = new IntegrtaionResult();
            FrayteResult      FR     = new FrayteResult();
            //string xsUserFolder = @"C:\FMS\" + "FrayteSchedularlog.txt";
            string xsUserFolder = @"D:\ProjectFrayte\" + "FrayteScheduler.txt";

            BaseLog.Instance.SetLogFile(xsUserFolder);
            Logger _log                = Get_Log();
            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
            _log.Error("Get direct Booking Object");
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);
            _log.Error("saved direct Booking Object");
            //step1. Mapping With directBookingDetail to ShipmentRequestDto
            var shipmentRequestDto = new DHLRepository().MapDirectBookingDetailToDHLShipmentRequestDto(directBookingDetail);

            //Step 2. Create Xml
            var shipmentXML = new DHLRepository().CreateXMLForDHL(shipmentRequestDto);
            _log.Error("done xml dhl shipment");
            _log.Error(shipmentXML);
            string xml_in = "";
            try
            {
                xml_in = File.ReadAllText(shipmentXML);
                //xml_in = File.ReadAllText(@"C:\FMS\app.godemowithus.com\WebApi\UploadFiles\PDFGenerator\HTMLFile\tempDHLShipment.xml");
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                _log.Error(e.InnerException);
                _log.Error(e.StackTrace);
            }
            _log.Error("reading xml dhl shipment");
            //step 3. Create Shipment
            var DHLResponse = new DHLRepository().CreateShipment(xml_in, shipmentRequestDto);
            // _log.Error("done integration dhl shipment" + DHLResponse.Error.ErrorDescription.ToString());
            //step 4. Mapping ShipmentResonse to IntegrtaionResult
            result = new DHLRepository().MapDHLIntegrationResponse(DHLResponse);
            if (result.Status)
            {
                //step2. After Shipment Create need to save the information in database
                DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, result);
                if (DirectShipmentid > 0)
                {
                    _log.Error("done save dhl shipment in db" + directBookingDetail.CustomerId);
                    var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                    _log.Error(Id.ToString());
                }
                _log.Error("done save dhl shipment in db");
                if (directBookingDetail.CustomerRateCard.CourierName == FrayteCourierCompany.DHL)
                {
                    //Step 1.1 Mapping ShipmentResult to IntegrtaionResult
                    new DHLRepository().MappingCourierPieceDetail(result, directBookingDetail, DirectShipmentid);
                }

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

                //Step4:  //Start downloading the images from UPS server and making PDF

                var count      = 1;
                var totalpiece = result.PieceTrackingDetails.Count();
                totalpiece = totalpiece - 1;
                foreach (var data in result.PieceTrackingDetails.Take(totalpiece))
                {
                    if (directBookingDetail.CustomerRateCard.CourierName == FrayteCourierCompany.DHL)
                    {
                        _log.Error("downloading shipment image");
                        //Step3.1
                        data.LabelName = new DHLRepository().DownloadDHLImage(data, totalpiece, count, DirectShipmentid);
                        _log.Error("downloaded shipment image");
                    }

                    //// Step3.2
                    //new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    //_log.Error("saved package detail shipment image");
                    if (!data.PieceTrackingNumber.Contains("AirwayBillNumber_"))
                    {
                        // Step3.2
                        new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    }
                    count++;
                }
                var CourierPieceDetail = result.PieceTrackingDetails.Where(t => t.PieceTrackingNumber.Contains("AirwayBillNumber_")).FirstOrDefault();
                if (CourierPieceDetail != null)
                {
                    var data1 = new DHLRepository().DownloadDHLImage(CourierPieceDetail, totalpiece, 0, DirectShipmentid);
                }
                if (result != null)
                {
                    directBookingDetail.Error        = new FratyteError();
                    directBookingDetail.Error.Status = result.Status;
                }

                return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
            }
            else
            {
                directBookingDetail.Error = result.Error;
                new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, directBookingDetail.CustomerId);
                //Send mail to developer
                new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, directBookingDetail.Error);
            }
            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
        }
コード例 #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());
        }