From fa392dfca4b5d91871e1153b981cac9a3106778e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 24 Mar 2025 11:07:48 +0330 Subject: [PATCH] a small improvement on generating thank you emails text for donars --- GanjooRazor/Areas/Admin/Pages/Donations.cshtml.cs | 15 ++++++++++++++- GanjooRazor/Areas/User/Pages/CatEditor.cshtml.cs | 12 +++--------- RMuseum/Utils/GanjoorPoemTools.cs | 14 +++++++++++++- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/GanjooRazor/Areas/Admin/Pages/Donations.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/Donations.cshtml.cs index bc566b9e..98439835 100644 --- a/GanjooRazor/Areas/Admin/Pages/Donations.cshtml.cs +++ b/GanjooRazor/Areas/Admin/Pages/Donations.cshtml.cs @@ -2,13 +2,16 @@ using System.Linq; using System.Net.Http; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; +using System.Web; using DNTPersianUtils.Core; using GanjooRazor.Utils; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Newtonsoft.Json; using RMuseum.Models.Accounting.ViewModels; +using RMuseum.Utils; namespace GanjooRazor.Areas.Admin.Pages { @@ -78,6 +81,7 @@ namespace GanjooRazor.Areas.Admin.Pages } } + public async Task OnGetAsync() { if (string.IsNullOrEmpty(Request.Cookies["Token"])) @@ -100,7 +104,16 @@ namespace GanjooRazor.Areas.Admin.Pages if(donation != null) { int rowNumber = Donations.Length - Array.IndexOf(Donations, donation); - EmailContent = $"با درود به {donation.DonorName} عزیز و سپاس از بزرگواری شما{Environment.NewLine}" + + string donorName = GanjoorPoemTools.StripHtmlTags(donation.DonorName); + if(donorName.StartsWith("آقای")) + { + donorName = $"جناب {donorName}"; + } + if (donorName.StartsWith("خانم")) + { + donorName = $"سرکار {donorName}"; + } + EmailContent = $"با درود به {donorName} عزیز و سپاس از بزرگواری شما{Environment.NewLine}" + $"کمک دریافتی به شماره ردیف {rowNumber.ToPersianNumbers()} در این نشانی ثبت شد:{Environment.NewLine}" + $"https://ganjoor.net/donate{Environment.NewLine}" + $"نحوهٔ هزینه شدن آن متعاقباً در همان ردیف مستند خواهد شد.{Environment.NewLine}" + diff --git a/GanjooRazor/Areas/User/Pages/CatEditor.cshtml.cs b/GanjooRazor/Areas/User/Pages/CatEditor.cshtml.cs index df748e23..91328372 100644 --- a/GanjooRazor/Areas/User/Pages/CatEditor.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/CatEditor.cshtml.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System; using System.Text.RegularExpressions; using System.Web; +using RMuseum.Utils; namespace GanjooRazor.Areas.User.Pages { @@ -118,20 +119,13 @@ namespace GanjooRazor.Areas.User.Pages return new BadRequestObjectResult("لطفاً از گنجور خارج و مجددا به آن وارد شوید."); } - static string StripHtmlTags(string input) - { - // Remove HTML tags using Regex - string textWithoutTags = Regex.Replace(input, "<.*?>", string.Empty); - - // Decode HTML entities (e.g., & → &) - return HttpUtility.HtmlDecode(textWithoutTags); - } + public async Task OnPostAsync() { try { - Correction.Description = StripHtmlTags(Correction.DescriptionHtml); + Correction.Description = GanjoorPoemTools.StripHtmlTags(Correction.DescriptionHtml); using (HttpClient secureClient = new HttpClient()) { if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) diff --git a/RMuseum/Utils/GanjoorPoemTools.cs b/RMuseum/Utils/GanjoorPoemTools.cs index 3da3dea3..a1f5bd9b 100644 --- a/RMuseum/Utils/GanjoorPoemTools.cs +++ b/RMuseum/Utils/GanjoorPoemTools.cs @@ -1,4 +1,7 @@ -namespace RMuseum.Utils +using System.Text.RegularExpressions; +using System.Web; + +namespace RMuseum.Utils { /// /// ganjoor poem tools @@ -37,5 +40,14 @@ return poemHtml; } + + public static string StripHtmlTags(string input) + { + // Remove HTML tags using Regex + string textWithoutTags = Regex.Replace(input, "<.*?>", string.Empty); + + // Decode HTML entities (e.g., & → &) + return HttpUtility.HtmlDecode(textWithoutTags); + } } }