添加配置页面

blazor
Patrick BRUGIERE 1 year ago
parent 07b3d6bb56
commit 793d8fab77

@ -0,0 +1,30 @@
using System.Data;
namespace adminBlazor.Models
{
public class UserOptions
{
public const string User = "User";
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Nickname { get; set; }
public bool ExtraTime { get; set; }
public int Group { get; set; }
public List<string> Roles { get; set; }
public UserOptions()
{
// Constructeur sans paramètre public
Id = 1;
Name = "DefaultName";
Surname = "DefaultSurname";
Nickname = "DefaultNickname";
ExtraTime = false;
Group = 0;
Roles = new List<string>();
}
}
}

@ -0,0 +1,16 @@
@page "/config"
<h3>Config</h3>
@if (userOptions != null)
{
<div>
<div>Title: @userOptions.Id</div>
<div>Name: @userOptions.Name</div>
<div>Surname: @userOptions.Surname</div>
<div>Nickname: @userOptions.Nickname</div>
<div>ExtraTime: @userOptions.ExtraTime</div>
<div>Group: @userOptions.Group</div>
<div>Roles: @string.Join(", ", userOptions.Roles)</div>
</div>
}

@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Components;
using adminBlazor.Models;
using Microsoft.Extensions.Options;
namespace adminBlazor.Pages
{
public partial class Config
{
[Inject]
public IConfiguration Configuration { get; set; }
private UserOptions userOptions;
protected override void OnInitialized()
{
base.OnInitialized();
userOptions = Configuration.GetSection(UserOptions.User).Get<UserOptions>();
}
}
}

@ -11,82 +11,86 @@ using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using adminBlazor.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddScoped<IDataService, DataLocalService>();
//builder.Services.AddScoped<IDataService, DataApiService>();
//builder.Services.AddScoped<IDataService, DataApiService>();
builder.Services.AddScoped<IVocListService, VocListLocalService>();
builder.Services.AddScoped<IVocListService, VocListLocalService>();
builder.Services.AddHttpClient();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazoredModal();
builder.Services.AddHttpClient();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazoredModal();
// Add the controller of the app
builder.Services.AddControllers();
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// Configure the localtization
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
// Set the default culture of the web site
options.DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US"));
// Configure the localtization
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
// Set the default culture of the web site
options.DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US"));
// Declare the supported culture
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
options.SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
});
// Declare the supported culture
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
options.SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
});
builder.Services
.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();
builder.Services
.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();
var app = builder.Build();
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();
}
// 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.UseStaticFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseRouting();
// Get the current localization options
var options = ((IApplicationBuilder)app).ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
// Get the current localization options
var options = ((IApplicationBuilder)app).ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
if (options?.Value != null)
{
// use the default localization
app.UseRequestLocalization(options.Value);
}
if (options?.Value != null)
{
// use the default localization
app.UseRequestLocalization(options.Value);
}
// Add the controller to the endpoint
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
// Add the controller to the endpoint
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
app.Run();

Loading…
Cancel
Save