Ejemplo n.º 1
0
 public ExpressEmailModel ExpressEmailObj(int shipmentId)
 {
     try
     {
         ExpressEmailModel model = new ExpressEmailModel();
         model.ShipmentDetail = new ExpressRepository().ScannedShipmentDetail(shipmentId, "");
         return(model);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        public FrayteResult SendLabelEmail(ExpressEmailModel emailModel)
        {
            FrayteResult result = new FrayteResult();

            emailModel.ImageHeader = "FrayteLogo";
            try
            {
                var operationzone = UtilityRepository.GetOperationZone();

                var result1 = (from s in dbContext.Expresses
                               join Usr in dbContext.Users on s.CustomerId equals Usr.UserId
                               join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                               join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId
                               join OU in dbContext.Users on UA.OperationUserId equals OU.UserId
                               join OUA in dbContext.UserAdditionals on OU.UserId equals OUA.UserId
                               where Usr.UserId == emailModel.ShipmentDetail.CustomerId
                               select new
                {
                    UserName = OU.ContactName,
                    Name = Usr.ContactName,
                    UserEmail = OU.Email,
                    UserPosition = OU.Position,
                    CutomerCompany = Usr.CompanyName
                }).FirstOrDefault();

                var detail = dbContext.CustomerCompanyDetails.Where(p => p.UserId == emailModel.ShipmentDetail.CustomerId).FirstOrDefault();

                if (detail != null)
                {
                    emailModel.StaffUserEmail  = detail.OperationStaffEmail;
                    emailModel.UserPosition    = detail.UserPosition;
                    emailModel.StaffUserName   = detail.OperationStaff;
                    emailModel.CompanyName     = detail.CompanyName;
                    emailModel.UserPhone       = detail.OperationStaffPhone;
                    emailModel.SiteAddress     = detail.SiteAddress;
                    emailModel.TrackingWebsite = detail.TrackingUrl + "/#/tracking/" + emailModel.ShipmentDetail.AWBNumber.Replace(" ", "");
                    emailModel.TrackingURL     = detail.TrackingUrl + "/#/tracking/" + emailModel.ShipmentDetail.TrackingNumber.Replace("Order_", "");
                }
                else
                {
                    emailModel.UserEmail       = result1.UserEmail;
                    emailModel.UserName        = result1.UserName;
                    emailModel.UserPosition    = result1.UserPosition;
                    emailModel.SiteCompany     = "FRAYTE GLOBAL";
                    emailModel.UserPhone       = UtilityRepository.GetOperationZone().OperationZoneId == 1 ? "(+852) 2148 4880" : "(+44) 01792 277295";
                    emailModel.SiteAddress     = UtilityRepository.GetOperationZone().OperationZoneId == 1 ? "www.FRAYTE.com" : "www.FRAYTE.co.uk";
                    emailModel.TrackingWebsite = UtilityRepository.GetOperationZone().OperationZoneId == 1 ? "https://frayte.com/tracking-detail/" + emailModel.ShipmentDetail.AWBNumber.Replace(" ", "") : "https://frayte.co.uk/tracking-detail/" + emailModel.ShipmentDetail.AWBNumber.Replace(" ", "");
                    emailModel.TrackingURL     = AppSettings.TrackingUrl + "/tracking-detail/" + emailModel.ShipmentDetail.TrackingNumber.Replace("Order_", "");;
                }

                emailModel.TotalCarton = emailModel.ShipmentDetail.Packages.Sum(p => p.CartonValue);
                emailModel.TotalWeight = emailModel.ShipmentDetail.Packages.Sum(p => p.CartonValue * p.Weight);
                emailModel.CreatedOn   = emailModel.ShipmentDetail.CreatedOnUtc != null?emailModel.ShipmentDetail.CreatedOnUtc.ToString("dd-MMM-yyyy hh:mm") : "";

                emailModel.CustomerName = result1.Name;
                string template = File.ReadAllText(AppSettings.EmailServicePath + "/EmailTeamplate/Express/EXS_E1_3.cshtml");

                var    templateService = new TemplateService();
                var    EmailBody       = templateService.Parse(template, emailModel, null, null);
                string EmailSubject    = string.Empty;
                EmailSubject = result1.CutomerCompany + " - Shipment Detail with Label - " + emailModel.ShipmentDetail.AWBNumber;

                var To     = emailModel.To;
                var Status = "";

                #region Attach Labels

                string Attachment = PackageLabelPath_EXS_E1(emailModel.ShipmentDetail.ExpressId);

                #endregion

                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Customer Email " + emailModel.ShipmentDetail.FrayteNumber));
                //Send mail to Customer
                Send_FrayteEmail(To, AppSettings.TOCC, "FRAYTE - Booking (" + UtilityRepository.OperationZoneName(operationzone.OperationZoneId) + ")", EmailSubject, EmailBody, Attachment, Status, emailModel.ShipmentDetail.CustomerId);
                result.Status = true;
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(EmailBody));
            }
            catch (Exception ex)
            {
                result.Status = false;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void SendMissingAWBsMail(List <ExpressMissingShipmentModel> Awbs, int UserId)
        {
            ExpressEmailModel Res = new ExpressEmailModel();

            Res.ImageHeader = "FrayteLogo";
            Res.TotalMawb   = Awbs.Count;
            //foreach (var mawb in Mawbs)
            //{
            //    MawbCount = MawbCount + mawb.GrossWeight
            //}
            Res.MissingAwbs = Awbs;

            Res.TotalWeight = Awbs.Sum(a => a.TotalWeight);
            Res.ShipInfo    = new List <ExpressMissingShipmentsInfo>();
            Res.TotalAwbs   = Awbs.Count;
            Res.CreatedOn   = DateTime.UtcNow.Date.AddDays(-1).ToString("dd-MMM-yyyy");
            string        logoImage = AppSettings.EmailServicePath + "/Images/FrayteLogo.png";
            List <string> ImagePath = new List <string>();

            ImagePath.Add(logoImage);
            var    OperationName = UtilityRepository.GetOperationZone();
            string Site          = string.Empty;

            if (OperationName.OperationZoneId == 1)
            {
                //Res.SiteAddress = AppSettings.TrackingUrl;
            }
            else if (OperationName.OperationZoneId == 2)
            {
                //Res.SiteAddress = AppSettings.TrackingUrl;
            }
            Res.ImageHeader = "FrayteLogo";
            string OperationUserEmail = "";
            int    RoleId             = 0;
            var    Email = "";

            var result = (from Usr in dbContext.Users
                          join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                          join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId
                          where Usr.UserId == UserId
                          select new
            {
                Usr.UserEmail,
                Rl.RoleId,
                Usr.ContactName,
                Usr.CompanyName,
                UA.OperationUserId
            }).FirstOrDefault();

            if (result != null)
            {
                RoleId = result.RoleId;
                Email  = result.UserEmail;
                Res.CustomerCompanyName = result.CompanyName;
            }

            var result1 = (from Usr in dbContext.Users
                           join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                           join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId
                           where Usr.UserId == result.OperationUserId
                           select new
            {
                Usr.Email,
                Rl.RoleId,
                Usr.ContactName,
                Usr.CompanyName,
                UA.OperationUserId,
                Usr.Position
            }).FirstOrDefault();

            if (result1 != null)
            {
                RoleId             = result1.RoleId;
                OperationUserEmail = result1.Email;
            }
            if (OperationName.OperationZoneId == 1)
            {
                Res.UserEmail     = result1.Email;
                Res.UserName      = result1.ContactName;
                Res.UserPosition  = result1.Position;
                Res.CustomerName  = result.ContactName;
                Res.CustomerEmail = result.UserEmail;
                Res.SystemEmail   = "*****@*****.**";
                Res.UserPhone     = "(+852) 2148 4880";
                //Res.SiteAddress = AppSettings.TrackingUrl;
                Res.Site = "www.FRAYTE.com";
            }
            if (OperationName.OperationZoneId == 2)
            {
                Res.UserEmail     = result1.Email;
                Res.UserPosition  = result1.Position;
                Res.UserName      = result1.ContactName;
                Res.CustomerName  = result.ContactName;
                Res.CustomerEmail = result.UserEmail;
                Res.SystemEmail   = "*****@*****.**";
                Res.UserPhone     = "(+44) 01792 277295";
                // Res.SiteAddress = AppSettings.TrackingUrl;
                Res.Site = "www.FRAYTE.co.uk";
            }

            string template     = File.ReadAllText(AppSettings.EmailServicePath + "/EmailTeamplate/Express/EXS_E4.cshtml");
            var    EmailBody    = Engine.Razor.RunCompile(template, "Usr4", null, Res, null);
            var    EmailSubject = "";
            var    Mawbvar      = "";
            var    Status       = "";

            if (!string.IsNullOrEmpty(Res.CustomerCompanyName))
            {
                EmailSubject = Res.CustomerCompanyName + " - EXS Discrepancies Shipment Summary – " + DateTime.UtcNow.Date.AddDays(-1).ToString("dd-MMM-yyyy");
            }

            FrayteEmail.SendMail(Email, "", EmailSubject, EmailBody, "", logoImage);

            ExpressSchedulerEmail ExpSchEm1 = new ExpressSchedulerEmail();

            ExpSchEm1.CustomerId   = UserId;
            ExpSchEm1.EmailSentOn  = DateTime.UtcNow.Date;
            ExpSchEm1.EmailContent = EmailBody;
            dbContext.ExpressSchedulerEmails.Add(ExpSchEm1);
            dbContext.SaveChanges();
        }
Ejemplo n.º 4
0
        public void SendPODAWBsMail(List <ExpressDispatchedMawbModel> Mawbs, List <ExpressShipmentBookedConsolidateModel> Shipments, int UserId)
        {
            ExpressEmailModel Res = new ExpressEmailModel();

            Res.TotalMawb       = Mawbs.Count;
            Res.DispatchedMawbs = Mawbs;
            Res.AWbShipmentList = Shipments;
            var Hubs = Shipments.Select(a => a.HubCode).Distinct();

            Res.ShipList = new List <ExpressHubShipmentCountModel>();

            foreach (var h in Hubs)
            {
                var ShipmentCount = 0;

                foreach (var Sh in Shipments)
                {
                    if (h == Sh.HubCode)
                    {
                        ShipmentCount = ShipmentCount + Sh.Shipments.Count;
                    }
                }
                Res.ShipList.Add(new ExpressHubShipmentCountModel {
                    HubCode = h, ShipmentCount = ShipmentCount
                });
            }

            Res.TotalWeight = Mawbs.Sum(a => a.GrossWeight);
            Res.ShipInfo    = new List <ExpressMissingShipmentsInfo>();

            Res.TotalAwbs = 0;
            for (int i = 0; i < Shipments.Count; i++)
            {
                Res.TotalAwbs = Res.TotalAwbs + Shipments[i].Shipments.Count;
            }

            Res.CreatedOn = DateTime.UtcNow.Date.AddDays(-1).ToString("dd-MMM-yyyy");
            string        logoImage = AppSettings.EmailServicePath + "/Images/FrayteLogo.png";
            List <string> ImagePath = new List <string>();

            ImagePath.Add(logoImage);
            var OperationName = UtilityRepository.GetOperationZone();

            Res.ImageHeader = "FrayteLogo";
            string OperationUserEmail = "";
            int    RoleId             = 0;
            var    Email = "";

            var result = (from Usr in dbContext.Users
                          join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                          join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId
                          where Usr.UserId == UserId
                          select new
            {
                Usr.UserEmail,
                Rl.RoleId,
                Usr.ContactName,
                Usr.CompanyName,
                UA.OperationUserId
            }).FirstOrDefault();

            if (result != null)
            {
                RoleId = result.RoleId;
                Email  = result.UserEmail;
                Res.CustomerCompanyName = result.CompanyName;
            }

            var result1 = (from Usr in dbContext.Users
                           join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                           join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId
                           where Usr.UserId == result.OperationUserId
                           select new
            {
                Usr.Email,
                Rl.RoleId,
                Usr.ContactName,
                Usr.CompanyName,
                UA.OperationUserId,
                Usr.Position
            }).FirstOrDefault();

            if (result1 != null)
            {
                RoleId             = result1.RoleId;
                OperationUserEmail = result1.Email;
            }

            if (OperationName.OperationZoneId == 1)
            {
                Res.UserEmail     = result1.Email;
                Res.UserName      = result1.ContactName;
                Res.UserPosition  = result1.Position;
                Res.CustomerName  = result.ContactName;
                Res.CustomerEmail = result.UserEmail;
                Res.SystemEmail   = "*****@*****.**";
                Res.UserPhone     = "(+852) 2148 4880";
                //Res.SiteAddress = AppSettings.TrackingUrl;
                Res.Site = "www.FRAYTE.com";
            }

            if (OperationName.OperationZoneId == 2)
            {
                Res.UserEmail     = result1.Email;
                Res.UserPosition  = result1.Position;
                Res.UserName      = result1.ContactName;
                Res.CustomerName  = result.ContactName;
                Res.CustomerEmail = result.UserEmail;
                Res.SystemEmail   = "*****@*****.**";
                Res.UserPhone     = "(+44) 01792 277295";
                // Res.SiteAddress = AppSettings.TrackingUrl;
                Res.Site = "www.FRAYTE.co.uk";
            }

            string template     = File.ReadAllText(AppSettings.EmailServicePath + "/EmailTeamplate/Express/EXS_E2_POD.cshtml");
            var    EmailBody    = Engine.Razor.RunCompile(template, "Usr3", null, Res, null);
            var    EmailSubject = "";
            var    Mawbvar      = "";
            var    Status       = "";

            if (!string.IsNullOrEmpty(Res.CustomerCompanyName))
            {
                EmailSubject = Res.CustomerCompanyName + " - EXS POD Summary   – " + DateTime.UtcNow.Date.AddDays(-1).ToString("dd-MMM-yyyy");
            }

            FrayteEmail.SendMail(Email, "", EmailSubject, EmailBody, "", logoImage);

            ExpressSchedulerEmail ExpSchEm1 = new ExpressSchedulerEmail();

            ExpSchEm1.CustomerId   = UserId;
            ExpSchEm1.EmailSentOn  = DateTime.UtcNow.Date;
            ExpSchEm1.EmailContent = EmailBody;
            dbContext.ExpressSchedulerEmails.Add(ExpSchEm1);
            dbContext.SaveChanges();
        }
Ejemplo n.º 5
0
        public FrayteResult SendExportManifest(ExpressEmailModel emailModel, string FilePath, int UserId)
        {
            FrayteResult result = new FrayteResult();

            emailModel.ImageHeader = "FrayteLogo";
            try
            {
                var operationzone = UtilityRepository.GetOperationZone();

                var result1 = (from Usr in dbContext.Users
                               join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                               join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId into UAA
                               from UA in UAA.DefaultIfEmpty()
                               join OU in dbContext.Users on UA.OperationUserId equals OU.UserId into OUU
                               from OU in OUU.DefaultIfEmpty()
                               where Usr.UserId == emailModel.ManifestDetail.CustomerId
                               select new
                {
                    UserName = OU.ContactName,
                    CustomerName = Usr.ContactName,
                    StaffEmail = OU.Email,
                    UserEmail = Rl.RoleId == 3 ? Usr.UserEmail : Usr.Email,
                    UserPosition = OU.Position,
                    CutomerCompany = Usr.CompanyName
                }).FirstOrDefault();

                var result2 = (from Usr in dbContext.Users
                               join Rl in dbContext.UserRoles on Usr.UserId equals Rl.UserId
                               join UA in dbContext.UserAdditionals on Usr.UserId equals UA.UserId into UAA
                               from UA in UAA.DefaultIfEmpty()
                               join OU in dbContext.Users on UA.OperationUserId equals OU.UserId into OUU
                               from OU in OUU.DefaultIfEmpty()
                               where Usr.UserId == UserId
                               select new
                {
                    UserName = Usr.ContactName,
                    StaffEmail = OU.Email,
                    UserEmail = Rl.RoleId == 3 ? Usr.UserEmail : Usr.Email,
                    UserPosition = OU.Position,
                    CutomerCompany = Usr.CompanyName
                }).FirstOrDefault();


                if (operationzone.OperationZoneId == 1)
                {
                    emailModel.UserEmail    = result1.StaffEmail;
                    emailModel.UserName     = result1.UserName;
                    emailModel.UserPosition = result1.UserPosition;
                    emailModel.UserPhone    = "(+852) 2148 4880";
                    //Res.SiteAddress = AppSettings.TrackingUrl;
                    emailModel.SiteCompany = "FRAYTE GLOBAL";
                    emailModel.SiteAddress = "www.FRAYTE.com";
                }
                if (operationzone.OperationZoneId == 2)
                {
                    emailModel.UserEmail    = result1.StaffEmail;
                    emailModel.UserName     = result1.UserName;
                    emailModel.UserPosition = result1.UserPosition;
                    emailModel.SiteCompany  = "FRAYTE GLOBAL";
                    emailModel.UserPhone    = "(+44) 01792 277295";
                    // Res.SiteAddress = AppSettings.TrackingUrl;
                    emailModel.SiteAddress = "www.FRAYTE.co.uk";
                }

                emailModel.CreatedOn = emailModel.ManifestDetail.CreatedOn != null?emailModel.ManifestDetail.CreatedOn.Value.ToString("dd-MMM-yyyy hh:mm") : "";

                emailModel.CustomerName = result2.UserName;
                string template = File.ReadAllText(AppSettings.EmailServicePath + "/EmailTeamplate/Express/EXS_E5.cshtml");

                var    templateService = new TemplateService();
                var    EmailBody       = templateService.Parse(template, emailModel, null, null);
                string EmailSubject    = string.Empty;
                EmailSubject = result1.CutomerCompany + " - Origin Manifest  - " + emailModel.ManifestDetail.MAWB;

                var To     = result2.UserEmail;
                var Status = "";

                #region Attach Labels

                string Attachment = FilePath;
                //string Attachment = "";

                #endregion

                //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Customer Email " + emailModel.ShipmentDetail.FrayteNumber));
                //Send mail to Customer
                Send_FrayteEmail(To, AppSettings.TOCC, "FRAYTE - Booking (" + UtilityRepository.OperationZoneName(operationzone.OperationZoneId) + ")", EmailSubject, EmailBody, Attachment, Status, emailModel.ManifestDetail.CustomerId);
                result.Status = true;
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(EmailBody));
            }
            catch (Exception ex)
            {
                result.Status = false;
            }
            return(result);
        }
Ejemplo n.º 6
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());
        }