diff --git a/Altob.NtuInvoiceGateway/Altob.NtuInvoiceGateway.csproj b/Altob.NtuInvoiceGateway/Altob.NtuInvoiceGateway.csproj index 5a25aeb..66267b6 100644 --- a/Altob.NtuInvoiceGateway/Altob.NtuInvoiceGateway.csproj +++ b/Altob.NtuInvoiceGateway/Altob.NtuInvoiceGateway.csproj @@ -1,9 +1,14 @@ - - net9.0 - enable - enable - + + net9.0 + enable + enable + + + + + + diff --git a/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs b/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs index 83dcf2a..c761ccf 100644 --- a/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs +++ b/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs @@ -33,6 +33,7 @@ public class InvoiceModel : PageModel public InvoiceRequest InvoiceData { get; set; } = new(); public string? ErrorMessage { get; set; } + [TempData] public string? SuccessMessage { get; set; } public string CompanyName => _companyInfo.Name; public string CompanyTaxId => _companyInfo.TaxId; @@ -43,6 +44,7 @@ public class InvoiceModel : PageModel public void OnGet() { + RestoreDisplayValuesFromTempData(); // GET 方法保留為空,主要接收方式改為 POST JSON } @@ -196,8 +198,11 @@ public class InvoiceModel : PageModel if (apiResponse?.msgCode == "0000") { SuccessMessage = "發票資訊提交成功!"; + TempData[nameof(DisplayTransDateTime)] = DisplayTransDateTime; + TempData[nameof(DisplayTransAmount)] = DisplayTransAmount; _logger.LogInformation("{ServiceName} - {ActionName} submitted successfully for OrderID: {OrderID}", ServiceName, actionName, InvoiceData.OrderID); + return RedirectToPage(); } else { @@ -236,4 +241,19 @@ public class InvoiceModel : PageModel InvoiceData.LoveCode = InvoiceData.LoveCode ?? string.Empty; InvoiceData.TaxType = InvoiceData.TaxType ?? string.Empty; } + + private void RestoreDisplayValuesFromTempData() + { + if (TempData.TryGetValue(nameof(DisplayTransDateTime), out var transDateObj) && + transDateObj is string transDate) + { + DisplayTransDateTime = transDate; + } + + if (TempData.TryGetValue(nameof(DisplayTransAmount), out var amountObj) && + amountObj is string amount) + { + DisplayTransAmount = amount; + } + } } diff --git a/Altob.NtuInvoiceGateway/Program.cs b/Altob.NtuInvoiceGateway/Program.cs index efa201d..9a24c4c 100644 --- a/Altob.NtuInvoiceGateway/Program.cs +++ b/Altob.NtuInvoiceGateway/Program.cs @@ -1,5 +1,15 @@ +using Serilog; + var builder = WebApplication.CreateBuilder(args); +builder.Host.UseSerilog((context, services, configuration) => +{ + configuration + .ReadFrom.Configuration(context.Configuration) + .Enrich.FromLogContext() + .Enrich.WithProperty("ServiceName", "NtuInvoiceGateway"); +}); + // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddHttpClient(); @@ -12,22 +22,29 @@ builder.Services.Configure( var app = builder.Build(); -// Configure the HTTP request pipeline. -if (!app.Environment.IsDevelopment()) +try { - 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(); -} + // 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.UseHttpsRedirection(); -app.UseRouting(); + app.UseRouting(); -app.UseAuthorization(); + app.UseAuthorization(); -app.MapStaticAssets(); -app.MapRazorPages() - .WithStaticAssets(); + app.MapStaticAssets(); + app.MapRazorPages() + .WithStaticAssets(); -app.Run(); + app.Run(); +} +finally +{ + Log.CloseAndFlush(); +} diff --git a/Altob.NtuInvoiceGateway/appsettings.json b/Altob.NtuInvoiceGateway/appsettings.json index 532d850..730ffa3 100644 --- a/Altob.NtuInvoiceGateway/appsettings.json +++ b/Altob.NtuInvoiceGateway/appsettings.json @@ -5,6 +5,26 @@ "Microsoft.AspNetCore": "Information" } }, + "Serilog": { + "Using": [ "Serilog.Sinks.Seq" ], + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "System": "Warning" + } + }, + "WriteTo": [ + { + "Name": "Seq", + "Args": { + "serverUrl": "http://localhost:5341", + "apiKey": "" + } + } + ], + "Enrich": [ "FromLogContext" ] + }, "AllowedHosts": "*", "CompanyInfo": { "Name": "國立台灣大學臨時停車場", diff --git a/Altob.NtuInvoiceGateway/wwwroot/favicon.ico b/Altob.NtuInvoiceGateway/wwwroot/favicon.ico index 63e859b..ef9890f 100644 Binary files a/Altob.NtuInvoiceGateway/wwwroot/favicon.ico and b/Altob.NtuInvoiceGateway/wwwroot/favicon.ico differ