public TradelaneFile GetDriverManifest(ExpressDownloadPDFModel DownloadPDFModel) { TradelaneFile File = new TradelaneShipmentsController().CreateDocument(DownloadPDFModel.TradelaneShipmentId, DownloadPDFModel.CustomerId, FrayteTradelaneShipmentDocumentEnum.DriverManifest, ""); File.FilePath = AppSettings.WebApiPath + "UploadFiles/Tradelane" + "/" + DownloadPDFModel.TradelaneShipmentId + "/" + File.FileName; File.TradelaneShipmentId = DownloadPDFModel.TradelaneShipmentId; if (File.FileName != null && File.FilePath != null) { var FilePath = AppSettings.UploadFolderPath + "/Tradelane" + "/" + DownloadPDFModel.TradelaneShipmentId + "/" + File.FileName; new ExpressManifestRepository().SendDriverManifest(DownloadPDFModel, FilePath); } return(File); }
public FrayteResult SendDriverManifest(ExpressEmailModel emailModel, string FilePath, ExpressDownloadPDFModel TL) { FrayteResult result = new FrayteResult(); emailModel.ImageHeader = "FrayteLogo"; try { var operationzone = UtilityRepository.GetOperationZone(); var exprtManifest = dbContext.ExpressManifests.Where(b => b.BarCode == emailModel.DriverManifestDetail.Barcode).FirstOrDefault(); if (exprtManifest != null) { emailModel.CreatedOn = exprtManifest != null?exprtManifest.CreatedOn.Value.ToString("dd-MMM-yyyy hh:mm") : ""; } 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 == TL.CustomerId select new { UserName = Usr.ContactName, StaffName = OU.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 == TL.UserId select new { UserName = OU.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.StaffName; 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.StaffName; 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.DriverManifestDetail != null ? emailModel.ShipmentDetail.CreatedOnUtc.ToString("dd-MMM-yyyy hh:mm") : ""; emailModel.CustomerName = result1.UserName; string template = File.ReadAllText(AppSettings.EmailServicePath + "/EmailTeamplate/Express/EXS_E5_1.cshtml"); var templateService = new TemplateService(); var EmailBody = templateService.Parse(template, emailModel, null, null); string EmailSubject = string.Empty; EmailSubject = result1.CutomerCompany + " - Destination Manifest - " + emailModel.DriverManifestDetail.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, TL.CustomerId); result.Status = true; Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(EmailBody)); } catch (Exception ex) { result.Status = false; } return(result); }