Example #1
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());
        }
Example #2
0
        public void MappingFrayteResponseToExpressBookingDetail(ExpressShipmentModel ExpressDetail, IntegrtaionResult intResult, ExpressShipmentResponseModel Response)
        {
            Response.ShipmentBookingId = ExpressDetail.ExpressId;
            Response.Status            = true;
            Response.Description       = "";
            Response.AWBNumber         = ExpressDetail.AWBNumber.Substring(0, 3) + " " + ExpressDetail.AWBNumber.Substring(3, 3) + " " + ExpressDetail.AWBNumber.Substring(6, 3) + " " + ExpressDetail.AWBNumber.Substring(9, 3);
            Response.TrackingNumber    = intResult.TrackingNumber.Replace("Order_", "");
            Response.CreatedOn         = DateTime.UtcNow.ToString("dd-MMM-yyyy");
            Response.Currency          = ExpressDetail.DeclaredCurrency.CurrencyCode;
            Response.FromAddress       = new FromAddressDto()
            {
                CompanyName = ExpressDetail.ShipFrom.CompanyName,
                FirstName   = ExpressDetail.ShipFrom.FirstName,
                LastName    = ExpressDetail.ShipFrom.LastName,
                Email       = ExpressDetail.ShipFrom.Email,
                Phone       = ExpressDetail.ShipFrom.Phone,
                Address     = new ShipAddressDto()
                {
                    Address1    = ExpressDetail.ShipFrom.Address,
                    Address2    = ExpressDetail.ShipFrom.Address2,
                    Area        = ExpressDetail.ShipFrom.Area,
                    City        = ExpressDetail.ShipFrom.City,
                    CountryCode = ExpressDetail.ShipFrom.Country.Code,
                    Postcode    = ExpressDetail.ShipFrom.PostCode,
                    State       = ExpressDetail.ShipFrom.State
                }
            };
            Response.ToAddress = new ToAddressDto()
            {
                CompanyName = ExpressDetail.ShipTo.CompanyName,
                FirstName   = ExpressDetail.ShipTo.FirstName,
                LastName    = ExpressDetail.ShipTo.LastName,
                Email       = ExpressDetail.ShipTo.Email,
                Phone       = ExpressDetail.ShipTo.Phone,
                Address     = new ShipAddressDto()
                {
                    Address1    = ExpressDetail.ShipTo.Address,
                    Address2    = ExpressDetail.ShipTo.Address2,
                    Area        = ExpressDetail.ShipTo.Area,
                    City        = ExpressDetail.ShipTo.City,
                    CountryCode = ExpressDetail.ShipTo.Country.Code,
                    Postcode    = ExpressDetail.ShipTo.PostCode,
                    State       = ExpressDetail.ShipTo.State
                }
            };

            Response.CustomInfo = new ApiCustomInformation()
            {
                ContentsType        = ExpressDetail.CustomInformation.ContentsType,
                ContentsExplanation = ExpressDetail.CustomInformation.ContentsExplanation,
                RestrictionType     = ExpressDetail.CustomInformation.RestrictionType,
                RestrictionComments = ExpressDetail.CustomInformation.RestrictionComments,
                CustomsSigner       = ExpressDetail.CustomInformation.CustomsSigner,
                NonDeliveryOption   = ExpressDetail.CustomInformation.NonDeliveryOption,
            };
            var FilesArray = Directory.GetFiles(AppSettings.WebApiPath + "/PackageLabel/Express/" + ExpressDetail.ExpressId);

            if (FilesArray.Length > 0)
            {
                var AllFile = FilesArray.Where(a => a.Contains("All")).FirstOrDefault();
                if (!string.IsNullOrEmpty(AllFile))
                {
                    Response.AllLlabelUrl = AppSettings.LabelVirtualPath + "/PackageLabel/Express/" + FilesArray.Where(a => a.Contains("All")).FirstOrDefault().Split('/').LastOrDefault();
                }
                else
                {
                    Response.AllLlabelUrl = AppSettings.LabelVirtualPath + "/PackageLabel/Express/" + FilesArray.FirstOrDefault().Split('/').LastOrDefault();
                }
            }
            else
            {
                Response.AllLlabelUrl = "";
            }
        }