2025-09-28 05:36:45 +03:30
using FluentValidation ;
2025-09-28 01:28:44 +03:30
using FrontOffice.Main.Utilities ;
2025-11-14 13:12:31 +03:30
using System.Net ;
2025-09-28 01:28:44 +03:30
var builder = WebApplication . CreateBuilder ( args ) ;
// Add services to the container.
builder . Services . AddRazorPages ( ) ;
builder . Services . AddServerSideBlazor ( ) ;
#region AddCommonServices
builder . Services . AddCommonServices ( ) ;
#endregion
#region AddGrpcServices
builder . Services . AddGrpcServices ( builder . Configuration ) ;
#endregion
2025-09-28 05:36:45 +03:30
#region FluentValidation
2025-09-28 01:28:44 +03:30
2025-09-28 05:36:45 +03:30
ValidatorOptions . Global . LanguageManager = new CustomFluentValidationLanguageManager ( ) ;
#endregion
2025-09-28 01:28:44 +03:30
var appSettings = builder . Configuration . Get < AppSettings > ( ) ;
2025-11-14 09:32:19 +03:30
if ( ! string . IsNullOrWhiteSpace ( appSettings ? . DownloadUrl ) )
{
UrlUtility . DownloadUrl = appSettings . DownloadUrl ;
}
else
{
UrlUtility . DownloadUrl = string . Empty ; // fallback to empty
}
2025-09-28 01:28:44 +03:30
2025-10-20 15:20:29 +03:30
builder . Services . Configure < EncryptionSettings > ( builder . Configuration . GetSection ( "EncryptionSettings" ) ) ;
builder . Services . AddSingleton < MobileNumberEncryptor > ( ) ;
2025-09-28 01:28:44 +03:30
var app = builder . Build ( ) ;
// Configure the HTTP request pipeline.
if ( ! app . Environment . IsDevelopment ( ) )
{
app . UseExceptionHandler ( "/Error" ) ;
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app . UseHsts ( ) ;
}
app . UseHttpsRedirection ( ) ;
app . UseStaticFiles ( ) ;
app . UseRouting ( ) ;
app . MapBlazorHub ( ) ;
app . MapFallbackToPage ( "/_Host" ) ;
2025-11-14 13:12:31 +03:30
app . MapGet ( "/contract/sample" , ( FrontOffice . Main . Utilities . Pdf . IHtmlToPdfService pdfService ) = >
{
var html = @"<h2 style='text-align:center'>قرارداد نمونه همکاری</h2><p>این یک متن نمونه برای قرارداد است که فقط جهت تست دانلود PDF قرار داده شده است.</p><ul><li>بند ۱ : استفاده صرفا مجاز.</li><li>بند ۲: رعایت قوانین لازم است.</li><li>بند ۳: مسئولیت اطلاعات با کاربر است.</li></ul><p class='small'>تاریخ تولید: " + DateTime . Now . ToString ( "yyyy/MM/dd HH:mm" ) + "</p>" ;
var bytes = pdfService . GeneratePdf ( html , "sample-contract" ) ;
return Results . File ( bytes , "application/pdf" , "sample-contract.pdf" ) ;
} ) ;
app . MapGet ( "/contract/generate" , ( string html , string? fileName , FrontOffice . Main . Utilities . Pdf . IHtmlToPdfService pdfService ) = >
{
var decoded = WebUtility . UrlDecode ( html ) ;
var safeName = string . IsNullOrWhiteSpace ( fileName ) ? "contract" : fileName . Trim ( ) ;
var bytes = pdfService . GeneratePdf ( decoded , safeName ) ;
return Results . File ( bytes , "application/pdf" , safeName + ".pdf" ) ;
} ) ;
2025-09-28 01:28:44 +03:30
app . Run ( ) ;
public class AppSettings
{
2025-11-14 09:32:19 +03:30
public required string DownloadUrl { get ; set ; }
2025-09-28 01:28:44 +03:30
}
2025-10-20 15:20:29 +03:30
public class EncryptionSettings
{
2025-11-14 09:32:19 +03:30
public required string Key { get ; set ; }
public required string IV { get ; set ; }
2025-10-20 15:20:29 +03:30
}