/// <summary> /// Get the schedule for specific insurance type (Motor or Home or Travel or Domestic) /// </summary> /// <param name="request">Schedule request.</param> /// <returns>Schedule file path.</returns> public DownloadScheduleResponse GetScheduleFilePath(DownloadScheuleRequest request) { try { string FilePath = string.Empty; if (request.InsuranceType == Constants.Insurance.Travel) { TravelInsurance travel = new TravelInsurance(); TravelSavedQuotationResponse travelresult = travel.GetSavedQuotationByPolicy(request.DocNo, "portal", request.AgentCode, request.IsEndorsement, request.EndorsementID); FilePath = this.CreateTravelSchudles(travelresult, false); } else if (request.InsuranceType == Constants.Insurance.Motor) { MotorInsurance motor = new MotorInsurance(); MotorSavedQuotationResponse motorresult = motor.GetSavedMotorPolicy(request.DocNo, "", request.AgentCode, request.IsEndorsement, request.EndorsementID, request.RenewalCount); FilePath = this.CreateMotorSchudles(motorresult.MotorPolicyDetails, false); } else if (request.InsuranceType == Constants.Insurance.DomesticHelp) { DomesticHelp domestic = new DomesticHelp(); DomesticHelpSavedQuotationResponse domesticresult = domestic.GetSavedDomesticPolicy(request.DocNo, request.AgentCode, request.IsEndorsement, request.EndorsementID); FilePath = this.CreateDomesticSchudles(domesticresult, false); } else { HomeInsurance home = new HomeInsurance(); HomeSavedQuotationResponse homeresult = home.GetSavedQuotationPolicy(request.DocNo, "", request.AgentCode, request.IsEndorsement, request.EndorsementID, request.RenewalCount); FilePath = CreateHomeSchudles(homeresult, false); } return(new DownloadScheduleResponse { FilePath = FilePath, IsTransactionDone = true }); } catch (Exception ex) { return(new DownloadScheduleResponse { IsTransactionDone = false, TransactionErrorMessage = ex.Message }); } }
/// <summary> /// Get domestic schedule. /// </summary> /// <param name="domestic">domestic policy properties.</param> /// <param name="isMailSend">Mail send to the client or not.</param> /// <returns>Schedule file path.</returns> public string CreateDomesticSchudles(DomesticHelpSavedQuotationResponse domestic, bool isMailSend = true) { try { string FileName = domestic.DomesticHelp.DocumentNo + ".pdf"; string FileSavePath = AppDomain.CurrentDomain.BaseDirectory + "/ScheduleDocuments/" + domestic.DomesticHelp.InsuredCode + "/" + domestic.DomesticHelp.DocumentNo + "/"; if (!System.IO.Directory.Exists(FileSavePath)) { System.IO.Directory.CreateDirectory(FileSavePath); } string FullPath = FileSavePath + FileName; //ExtensionMethods.CopyCompanyLogos(AppDomain.CurrentDomain.BaseDirectory + "/ScheduleDocuments/", FileSavePath); string htmlCode = File.ReadAllText(ExtensionMethods.CopyFile(AppDomain.CurrentDomain.BaseDirectory + "/Templates/DomesticHelp.html", FileSavePath + "DomesticHelp.html")); string DomesticWorkersDiv = System.IO.File.ReadAllText(ExtensionMethods.CopyFile(AppDomain.CurrentDomain.BaseDirectory + "/Templates/DomesticWorkersDiv.txt", FileSavePath + "DomesticWorkersDiv.txt")); string memberslist = string.Empty; string memebrs = string.Empty; int MembersCount = 1; foreach (var list in domestic.DomesticHelpMemberList) { string sex = list.Sex == 'M' ? "Male" : "Female"; memebrs = DomesticWorkersDiv.Replace("{{Name}}", list.Name) .Replace("{{SEX}}", sex) .Replace("{{DOB}}", list.DOB.CovertToLocalFormat()) .Replace("{{Nationality}}", list.Nationality) .Replace("{{CPR}}", list.CPRNumber) .Replace("{{Passport}}", list.Passport) .Replace("{{Occupation}}", list.Occupation) .Replace("{{Address}}", list.AddressType) .Replace("{{WorkerCount}}", Convert.ToString(MembersCount)); MembersCount++; memberslist += memebrs; } htmlCode = htmlCode.Replace("{{DomesticWorkersDiv}}", memberslist) .Replace("{{PolicyStartDate}}", domestic.DomesticHelp.PolicyStartDate.CovertToLocalFormat()) .Replace("{{PolicyExpiryDate}}", domestic.DomesticHelp.PolicyExpiryDate.CovertToLocalFormat()) .Replace("{{SumInsured}}", Convert.ToString(domestic.DomesticHelp.SumInsured)) .Replace("{{Premium}}", Convert.ToString(domestic.DomesticHelp.PremiumAfterDiscount)) .Replace("{{CurrentDate}}", DateTime.Now.CovertToLocalFormat()) .Replace("{{InsuredName}}", domestic.DomesticHelp.FullName) .Replace("{{EmployedUnder}}", domestic.DomesticHelp.DomesticWorkType) .Replace("{{PhysicalDefect}}", domestic.DomesticHelp.IsPhysicalDefect) .Replace("{{PolicyNo}}", domestic.DomesticHelp.DocumentNo) .Replace("{{Vat}}", Convert.ToString(domestic.DomesticHelp.TaxOnPremium)) .Replace("{{Total}}", Convert.ToString(domestic.DomesticHelp.PremiumAfterDiscount + domestic.DomesticHelp.TaxOnPremium)); if (System.IO.File.Exists(FullPath)) { System.IO.File.Delete(FullPath); } byte[] byteArray = Encoding.UTF8.GetBytes(htmlCode); MemoryStream stream = new MemoryStream(byteArray); HtmlToPdf.Generate(stream, FullPath, "", ""); return(FullPath); } catch (Exception ex) { return(""); } }