| @@ -1,9 +1,14 @@ | |||||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||
| <PropertyGroup> | |||||
| <TargetFramework>net9.0</TargetFramework> | |||||
| <Nullable>enable</Nullable> | |||||
| <ImplicitUsings>enable</ImplicitUsings> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup> | |||||
| <TargetFramework>net9.0</TargetFramework> | |||||
| <Nullable>enable</Nullable> | |||||
| <ImplicitUsings>enable</ImplicitUsings> | |||||
| </PropertyGroup> | |||||
| <ItemGroup> | |||||
| <PackageReference Include="Serilog.AspNetCore" Version="8.0.1" /> | |||||
| <PackageReference Include="Serilog.Sinks.Seq" Version="6.0.0" /> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> | ||||
| @@ -33,6 +33,7 @@ public class InvoiceModel : PageModel | |||||
| public InvoiceRequest InvoiceData { get; set; } = new(); | public InvoiceRequest InvoiceData { get; set; } = new(); | ||||
| public string? ErrorMessage { get; set; } | public string? ErrorMessage { get; set; } | ||||
| [TempData] | |||||
| public string? SuccessMessage { get; set; } | public string? SuccessMessage { get; set; } | ||||
| public string CompanyName => _companyInfo.Name; | public string CompanyName => _companyInfo.Name; | ||||
| public string CompanyTaxId => _companyInfo.TaxId; | public string CompanyTaxId => _companyInfo.TaxId; | ||||
| @@ -43,6 +44,7 @@ public class InvoiceModel : PageModel | |||||
| public void OnGet() | public void OnGet() | ||||
| { | { | ||||
| RestoreDisplayValuesFromTempData(); | |||||
| // GET 方法保留為空,主要接收方式改為 POST JSON | // GET 方法保留為空,主要接收方式改為 POST JSON | ||||
| } | } | ||||
| @@ -196,8 +198,11 @@ public class InvoiceModel : PageModel | |||||
| if (apiResponse?.msgCode == "0000") | if (apiResponse?.msgCode == "0000") | ||||
| { | { | ||||
| SuccessMessage = "發票資訊提交成功!"; | SuccessMessage = "發票資訊提交成功!"; | ||||
| TempData[nameof(DisplayTransDateTime)] = DisplayTransDateTime; | |||||
| TempData[nameof(DisplayTransAmount)] = DisplayTransAmount; | |||||
| _logger.LogInformation("{ServiceName} - {ActionName} submitted successfully for OrderID: {OrderID}", | _logger.LogInformation("{ServiceName} - {ActionName} submitted successfully for OrderID: {OrderID}", | ||||
| ServiceName, actionName, InvoiceData.OrderID); | ServiceName, actionName, InvoiceData.OrderID); | ||||
| return RedirectToPage(); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -236,4 +241,19 @@ public class InvoiceModel : PageModel | |||||
| InvoiceData.LoveCode = InvoiceData.LoveCode ?? string.Empty; | InvoiceData.LoveCode = InvoiceData.LoveCode ?? string.Empty; | ||||
| InvoiceData.TaxType = InvoiceData.TaxType ?? 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; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -1,5 +1,15 @@ | |||||
| using Serilog; | |||||
| var builder = WebApplication.CreateBuilder(args); | 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. | // Add services to the container. | ||||
| builder.Services.AddRazorPages(); | builder.Services.AddRazorPages(); | ||||
| builder.Services.AddHttpClient(); | builder.Services.AddHttpClient(); | ||||
| @@ -12,22 +22,29 @@ builder.Services.Configure<Altob.NtuInvoiceGateway.Models.InvoiceApiOptions>( | |||||
| var app = builder.Build(); | 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(); | |||||
| } | |||||
| @@ -5,6 +5,26 @@ | |||||
| "Microsoft.AspNetCore": "Information" | "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": "*", | "AllowedHosts": "*", | ||||
| "CompanyInfo": { | "CompanyInfo": { | ||||
| "Name": "國立台灣大學臨時停車場", | "Name": "國立台灣大學臨時停車場", | ||||