diff --git a/BlazorApp1/App.razor b/BlazorApp1/App.razor index 6fd3ed1..5a38683 100644 --- a/BlazorApp1/App.razor +++ b/BlazorApp1/App.razor @@ -1,4 +1,5 @@ - + + @@ -10,3 +11,4 @@ + \ No newline at end of file diff --git a/BlazorApp1/BlazorApp1.csproj b/BlazorApp1/BlazorApp1.csproj index c0eacf6..9354de1 100644 --- a/BlazorApp1/BlazorApp1.csproj +++ b/BlazorApp1/BlazorApp1.csproj @@ -8,9 +8,11 @@ + + diff --git a/BlazorApp1/Controllers/CultureController.cs b/BlazorApp1/Controllers/CultureController.cs new file mode 100644 index 0000000..0b60190 --- /dev/null +++ b/BlazorApp1/Controllers/CultureController.cs @@ -0,0 +1,35 @@ +using Microsoft.AspNetCore.Localization; +using Microsoft.AspNetCore.Mvc; + +namespace BlazorApp1.Controllers +{ + + /// + /// The culture controller. + /// + [Route("[controller]/[action]")] + public class CultureController : Controller + { + /// + /// Sets the culture. + /// + /// The culture. + /// The redirect URI. + /// + /// The action result. + /// + public IActionResult SetCulture(string culture, string redirectUri) + { + if (culture != null) + { + // Define a cookie with the selected culture + this.HttpContext.Response.Cookies.Append( + CookieRequestCultureProvider.DefaultCookieName, + CookieRequestCultureProvider.MakeCookieValue( + new RequestCulture(culture))); + } + + return this.LocalRedirect(redirectUri); + } + } +} diff --git a/BlazorApp1/Factories/ItemFactory.cs b/BlazorApp1/Factories/ItemFactory.cs new file mode 100644 index 0000000..d9cb4e1 --- /dev/null +++ b/BlazorApp1/Factories/ItemFactory.cs @@ -0,0 +1,48 @@ +using BlazorApp1.Models; + +namespace BlazorApp1.Factories +{ + public static class ItemFactory + { + public static ItemModel ToModel(Item item, byte[] imageContent) + { + return new ItemModel + { + Id = item.Id, + DisplayName = item.DisplayName, + Name = item.Name, + RepairWith = item.RepairWith, + EnchantCategories = item.EnchantCategories, + MaxDurability = item.MaxDurability, + StackSize = item.StackSize, + ImageContent = imageContent + }; + } + + public static Item Create(ItemModel model) + { + return new Item + { + Id = model.Id, + DisplayName = model.DisplayName, + Name = model.Name, + RepairWith = model.RepairWith, + EnchantCategories = model.EnchantCategories, + MaxDurability = model.MaxDurability, + StackSize = model.StackSize, + CreatedDate = DateTime.Now + }; + } + + public static void Update(Item item, ItemModel model) + { + item.DisplayName = model.DisplayName; + item.Name = model.Name; + item.RepairWith = model.RepairWith; + item.EnchantCategories = model.EnchantCategories; + item.MaxDurability = model.MaxDurability; + item.StackSize = model.StackSize; + item.UpdatedDate = DateTime.Now; + } + } +} diff --git a/BlazorApp1/Modals/DeleteConfirmation.razor b/BlazorApp1/Modals/DeleteConfirmation.razor new file mode 100644 index 0000000..a1b43d6 --- /dev/null +++ b/BlazorApp1/Modals/DeleteConfirmation.razor @@ -0,0 +1,10 @@ +
+ +

+ Are you sure you want to delete @item.DisplayName ? +

+ + + + +
diff --git a/BlazorApp1/Modals/DeleteConfirmation.razor.cs b/BlazorApp1/Modals/DeleteConfirmation.razor.cs new file mode 100644 index 0000000..a3e9a7c --- /dev/null +++ b/BlazorApp1/Modals/DeleteConfirmation.razor.cs @@ -0,0 +1,37 @@ +using BlazorApp1.Models; +using Blazored.Modal; +using Blazored.Modal.Services; +using Microsoft.AspNetCore.Components; + +namespace BlazorApp1.Modals +{ + public partial class DeleteConfirmation + { + [CascadingParameter] + public BlazoredModalInstance ModalInstance { get; set; } + + [Inject] + public IDataService DataService { get; set; } + + [Parameter] + public int Id { get; set; } + + private Item item = new Item(); + + protected override async Task OnInitializedAsync() + { + // Get the item + item = await DataService.GetById(Id); + } + + void ConfirmDelete() + { + ModalInstance.CloseAsync(ModalResult.Ok(true)); + } + + void Cancel() + { + ModalInstance.CancelAsync(); + } + } +} diff --git a/BlazorApp1/Pages/Add.razor.cs b/BlazorApp1/Pages/Add.razor.cs index 68c51af..6ba34ad 100644 --- a/BlazorApp1/Pages/Add.razor.cs +++ b/BlazorApp1/Pages/Add.razor.cs @@ -7,25 +7,11 @@ namespace BlazorApp1.Pages { public partial class Add { - [Inject] - public ILocalStorageService LocalStorage { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - [Inject] - public IWebHostEnvironment WebHostEnvironment { get; set; } - /// /// The default enchant categories. /// private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" }; - /// - /// The default repair with. - /// - private List repairWith = new List() { "oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks", "crimson_planks", "warped_planks" }; - /// /// The current item model /// @@ -35,44 +21,21 @@ namespace BlazorApp1.Pages RepairWith = new List() }; - private async void HandleValidSubmit() - { - // Get the current data - var currentData = await LocalStorage.GetItemAsync>("data"); - - // Simulate the Id - itemModel.Id = currentData.Max(s => s.Id) + 1; - - // Add the item to the current data - currentData.Add(new Item - { - Id = itemModel.Id, - DisplayName = itemModel.DisplayName, - Name = itemModel.Name, - RepairWith = itemModel.RepairWith, - EnchantCategories = itemModel.EnchantCategories, - MaxDurability = itemModel.MaxDurability, - StackSize = itemModel.StackSize, - CreatedDate = DateTime.Now - }); - - // Save the image - var imagePathInfo = new DirectoryInfo($"{WebHostEnvironment.WebRootPath}/images"); + /// + /// The default repair with. + /// + private List repairWith = new List() { "oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks", "crimson_planks", "warped_planks" }; - // Check if the folder "images" exist - if (!imagePathInfo.Exists) - { - imagePathInfo.Create(); - } + [Inject] + public IDataService DataService { get; set; } - // Determine the image name - var fileName = new FileInfo($"{imagePathInfo}/{itemModel.Name}.png"); + [Inject] + public NavigationManager NavigationManager { get; set; } - // Write the file content - await File.WriteAllBytesAsync(fileName.FullName, itemModel.ImageContent); + private async void HandleValidSubmit() + { + await DataService.Add(itemModel); - // Save the data - await LocalStorage.SetItemAsync("data", currentData); NavigationManager.NavigateTo("list"); } diff --git a/BlazorApp1/Pages/Counter.razor b/BlazorApp1/Pages/Counter.razor index ef23cb3..54d3a80 100644 --- a/BlazorApp1/Pages/Counter.razor +++ b/BlazorApp1/Pages/Counter.razor @@ -13,6 +13,6 @@ private void IncrementCount() { - currentCount++; + currentCount=currentCount+8000; } } diff --git a/BlazorApp1/Pages/Edit.razor b/BlazorApp1/Pages/Edit.razor new file mode 100644 index 0000000..c00eb38 --- /dev/null +++ b/BlazorApp1/Pages/Edit.razor @@ -0,0 +1,83 @@ +@page "/edit/{Id:int}" +@using BlazorApp1.Models + +

Edit

+ + + + + +

+ +

+

+ +

+

+ +

+

+ +

+

+ Enchant categories: +

+ @foreach (var item in enchantCategories) + { + + } +
+

+

+ Repair with: +

+ @foreach (var item in repairWith) + { + + } +
+

+

+ +

+

+ +

+

+ +

+ + +
\ No newline at end of file diff --git a/BlazorApp1/Pages/Edit.razor.cs b/BlazorApp1/Pages/Edit.razor.cs new file mode 100644 index 0000000..a393532 --- /dev/null +++ b/BlazorApp1/Pages/Edit.razor.cs @@ -0,0 +1,109 @@ +using BlazorApp1.Factories; +using BlazorApp1.Models; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; + +namespace BlazorApp1.Pages +{ + public partial class Edit + { + [Parameter] + public int Id { get; set; } + + /// + /// The default enchant categories. + /// + private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" }; + + /// + /// The current item model + /// + private ItemModel itemModel = new() + { + EnchantCategories = new List(), + RepairWith = new List() + }; + + /// + /// The default repair with. + /// + private List repairWith = new List() { "oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks", "crimson_planks", "warped_planks" }; + + [Inject] + public IDataService DataService { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + [Inject] + public IWebHostEnvironment WebHostEnvironment { get; set; } + + protected override async Task OnInitializedAsync() + { + var item = await DataService.GetById(Id); + + var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.png"); + + if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{itemModel.Name}.png")) + { + fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/{item.Name}.png"); + } + + // Set the model with the item + itemModel = ItemFactory.ToModel(item, fileContent); + } + + private async void HandleValidSubmit() + { + await DataService.Update(Id, itemModel); + + NavigationManager.NavigateTo("list"); + } + + private async Task LoadImage(InputFileChangeEventArgs e) + { + // Set the content of the image to the model + using (var memoryStream = new MemoryStream()) + { + await e.File.OpenReadStream().CopyToAsync(memoryStream); + itemModel.ImageContent = memoryStream.ToArray(); + } + } + + private void OnEnchantCategoriesChange(string item, object checkedValue) + { + if ((bool)checkedValue) + { + if (!itemModel.EnchantCategories.Contains(item)) + { + itemModel.EnchantCategories.Add(item); + } + + return; + } + + if (itemModel.EnchantCategories.Contains(item)) + { + itemModel.EnchantCategories.Remove(item); + } + } + + private void OnRepairWithChange(string item, object checkedValue) + { + if ((bool)checkedValue) + { + if (!itemModel.RepairWith.Contains(item)) + { + itemModel.RepairWith.Add(item); + } + + return; + } + + if (itemModel.RepairWith.Contains(item)) + { + itemModel.RepairWith.Remove(item); + } + } + } +} diff --git a/BlazorApp1/Pages/Index.razor b/BlazorApp1/Pages/Index.razor index 6085c4a..381542a 100644 --- a/BlazorApp1/Pages/Index.razor +++ b/BlazorApp1/Pages/Index.razor @@ -1,9 +1,11 @@ @page "/" +@using System.Globalization Index

Hello, world!

- Welcome to your new app. - +

+ CurrentCulture: @CultureInfo.CurrentCulture +

diff --git a/BlazorApp1/Pages/List.razor b/BlazorApp1/Pages/List.razor index 5ec4d95..bd9974b 100644 --- a/BlazorApp1/Pages/List.razor +++ b/BlazorApp1/Pages/List.razor @@ -1,10 +1,11 @@ @page "/list" @using BlazorApp1.Models +

@Localizer["Title"]

List

- + Ajouter
@@ -43,4 +44,10 @@ + + + Editer + + + \ No newline at end of file diff --git a/BlazorApp1/Pages/_Layout.cshtml b/BlazorApp1/Pages/_Layout.cshtml index 108ef35..fa86d76 100644 --- a/BlazorApp1/Pages/_Layout.cshtml +++ b/BlazorApp1/Pages/_Layout.cshtml @@ -12,6 +12,7 @@ + @RenderBody() @@ -28,7 +29,7 @@ - + diff --git a/BlazorApp1/Pages/list.razor.cs b/BlazorApp1/Pages/list.razor.cs index 9d9a230..d928e07 100644 --- a/BlazorApp1/Pages/list.razor.cs +++ b/BlazorApp1/Pages/list.razor.cs @@ -1,63 +1,65 @@ -using BlazorApp1.Models; +using BlazorApp1.Modals; +using BlazorApp1.Models; using Blazored.LocalStorage; +using Blazored.Modal; +using Blazored.Modal.Services; using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; namespace BlazorApp1.Pages { public partial class List { + [Inject] + public IStringLocalizer Localizer { get; set; } private List items; private int totalItem; [Inject] - public HttpClient Http { get; set; } + public NavigationManager NavigationManager { get; set; } - [Inject] - public ILocalStorageService LocalStorage { get; set; } + [CascadingParameter] + public IModalService Modal { get; set; } [Inject] - public IWebHostEnvironment WebHostEnvironment { get; set; } + public IDataService DataService { get; set; } [Inject] - public NavigationManager NavigationManager { get; set; } + public IWebHostEnvironment WebHostEnvironment { get; set; } - protected override async Task OnAfterRenderAsync(bool firstRender) + private async Task OnReadData(DataGridReadDataEventArgs e) { - // Do not treat this action if is not the first render - if (!firstRender) + if (e.CancellationToken.IsCancellationRequested) { return; } - var currentData = await LocalStorage.GetItemAsync("data"); - - // Check if data exist in the local storage - if (currentData == null) + if (!e.CancellationToken.IsCancellationRequested) { - // this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method) - var originalData = Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json").Result; - await LocalStorage.SetItemAsync("data", originalData); + items = await DataService.List(e.Page, e.PageSize); + totalItem = await DataService.Count(); } } - private async Task OnReadData(DataGridReadDataEventArgs e) + private async void OnDelete(int id) { - if (e.CancellationToken.IsCancellationRequested) + var parameters = new ModalParameters(); + parameters.Add(nameof(Item.Id), id); + + var modal = Modal.Show("Delete Confirmation", parameters); + var result = await modal.Result; + + if (result.Cancelled) { return; } - // When you use a real API, we use this follow code - //var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" ); - var response = (await LocalStorage.GetItemAsync("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); + await DataService.Delete(id); - if (!e.CancellationToken.IsCancellationRequested) - { - totalItem = (await LocalStorage.GetItemAsync>("data")).Count; - items = new List(response); // an actual data for the current page - } + // Reload the page + NavigationManager.NavigateTo("list", true); } } } diff --git a/BlazorApp1/Program.cs b/BlazorApp1/Program.cs index 7f683e4..7f5c9d2 100644 --- a/BlazorApp1/Program.cs +++ b/BlazorApp1/Program.cs @@ -1,10 +1,12 @@ using BlazorApp1.Data; using Blazored.LocalStorage; +using Blazored.Modal; using Blazorise; using Blazorise.Bootstrap; using Blazorise.Icons.FontAwesome; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Localization; +using Microsoft.Extensions.Options; +using System.Globalization; var builder = WebApplication.CreateBuilder(args); @@ -18,6 +20,25 @@ builder.Services .AddBootstrapProviders() .AddFontAwesomeIcons(); builder.Services.AddBlazoredLocalStorage(); +builder.Services.AddScoped(); +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"; }); + +// Configure the localtization +builder.Services.Configure(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 { new CultureInfo("en-US"), new CultureInfo("fr-FR") }; + options.SupportedUICultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") }; +}); var app = builder.Build(); @@ -35,6 +56,20 @@ app.UseStaticFiles(); app.UseRouting(); +var options = ((IApplicationBuilder)app).ApplicationServices.GetService>(); + +if (options?.Value != null) +{ + // use the default localization + app.UseRequestLocalization(options.Value); +} + +// Add the controller to the endpoint +app.UseEndpoints(endpoints => +{ + endpoints.MapControllers(); +}); + app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); diff --git a/BlazorApp1/Ressources/Pages.List.fr-FR.resx b/BlazorApp1/Ressources/Pages.List.fr-FR.resx new file mode 100644 index 0000000..65261b3 --- /dev/null +++ b/BlazorApp1/Ressources/Pages.List.fr-FR.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Liste + + \ No newline at end of file diff --git a/BlazorApp1/Ressources/Pages.List.resx b/BlazorApp1/Ressources/Pages.List.resx new file mode 100644 index 0000000..9d42237 --- /dev/null +++ b/BlazorApp1/Ressources/Pages.List.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + List + + \ No newline at end of file diff --git a/BlazorApp1/Services/DataLocalService.cs b/BlazorApp1/Services/DataLocalService.cs new file mode 100644 index 0000000..01833b0 --- /dev/null +++ b/BlazorApp1/Services/DataLocalService.cs @@ -0,0 +1,164 @@ +using BlazorApp1.Factories; +using BlazorApp1.Models; +using Blazored.LocalStorage; +using Microsoft.AspNetCore.Components; + +public class DataLocalService : IDataService +{ + private readonly HttpClient _http; + private readonly ILocalStorageService _localStorage; + private readonly NavigationManager _navigationManager; + private readonly IWebHostEnvironment _webHostEnvironment; + + public DataLocalService( + ILocalStorageService localStorage, + HttpClient http, + IWebHostEnvironment webHostEnvironment, + NavigationManager navigationManager) + { + _localStorage = localStorage; + _http = http; + _webHostEnvironment = webHostEnvironment; + _navigationManager = navigationManager; + } + + public async Task Add(ItemModel model) + { + // Get the current data + var currentData = await _localStorage.GetItemAsync>("data"); + + // Simulate the Id + model.Id = currentData.Max(s => s.Id) + 1; + + // Add the item to the current data + currentData.Add(ItemFactory.Create(model)); + + // Save the image + var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); + + // Check if the folder "images" exist + if (!imagePathInfo.Exists) + { + imagePathInfo.Create(); + } + + // Determine the image name + var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png"); + + // Write the file content + await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent); + + // Save the data + await _localStorage.SetItemAsync("data", currentData); + } + + public async Task Count() + { + return (await _localStorage.GetItemAsync("data")).Length; + } + + public async Task> List(int currentPage, int pageSize) + { + // Load data from the local storage + var currentData = await _localStorage.GetItemAsync("data"); + + // Check if data exist in the local storage + if (currentData == null) + { + // this code add in the local storage the fake data + var originalData = await _http.GetFromJsonAsync($"{_navigationManager.BaseUri}fake-data.json"); + await _localStorage.SetItemAsync("data", originalData); + } + + return (await _localStorage.GetItemAsync("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList(); + } + + +public async Task GetById(int id) + { + // Get the current data + var currentData = await _localStorage.GetItemAsync>("data"); + + // Get the item int the list + var item = currentData.FirstOrDefault(w => w.Id == id); + + // Check if item exist + if (item == null) + { + throw new Exception($"Unable to found the item with ID: {id}"); + } + + return item; + } + + public async Task Update(int id, ItemModel model) + { + // Get the current data + var currentData = await _localStorage.GetItemAsync>("data"); + + // Get the item int the list + var item = currentData.FirstOrDefault(w => w.Id == id); + + // Check if item exist + if (item == null) + { + throw new Exception($"Unable to found the item with ID: {id}"); + } + + // Save the image + var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); + + // Check if the folder "images" exist + if (!imagePathInfo.Exists) + { + imagePathInfo.Create(); + } + + // Delete the previous image + if (item.Name != model.Name) + { + var oldFileName = new FileInfo($"{imagePathInfo}/{item.Name}.png"); + + if (oldFileName.Exists) + { + File.Delete(oldFileName.FullName); + } + } + + // Determine the image name + var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png"); + + // Write the file content + await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent); + + ItemFactory.Update(item, model); + + // Save the data + await _localStorage.SetItemAsync("data", currentData); + + + } + public async Task Delete(int id) + { + // Get the current data + var currentData = await _localStorage.GetItemAsync>("data"); + + // Get the item int the list + var item = currentData.FirstOrDefault(w => w.Id == id); + + // Delete item in + currentData.Remove(item); + + // Delete the image + var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); + var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png"); + + if (fileName.Exists) + { + File.Delete(fileName.FullName); + } + + // Save the data + await _localStorage.SetItemAsync("data", currentData); + } +} \ No newline at end of file diff --git a/BlazorApp1/Services/IDataServicee.cs b/BlazorApp1/Services/IDataServicee.cs new file mode 100644 index 0000000..4b94277 --- /dev/null +++ b/BlazorApp1/Services/IDataServicee.cs @@ -0,0 +1,14 @@ +using BlazorApp1.Models; + +public interface IDataService +{ + Task Add(ItemModel model); + + Task Count(); + + Task> List(int currentPage, int pageSize); + Task GetById(int id); + + Task Update(int id, ItemModel model); + Task Delete(int id); +} \ No newline at end of file diff --git a/BlazorApp1/Shared/CultureSelector.razor b/BlazorApp1/Shared/CultureSelector.razor new file mode 100644 index 0000000..653175d --- /dev/null +++ b/BlazorApp1/Shared/CultureSelector.razor @@ -0,0 +1,43 @@ +@using System.Globalization +@inject NavigationManager NavigationManager + +

+ +

+ +@code +{ + private CultureInfo[] supportedCultures = new[] + { + new CultureInfo("en-US"), + new CultureInfo("fr-FR") + }; + + private CultureInfo Culture + { + get => CultureInfo.CurrentCulture; + set + { + if (CultureInfo.CurrentUICulture == value) + { + return; + } + + var culture = value.Name.ToLower(CultureInfo.InvariantCulture); + + var uri = new Uri(this.NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped); + var query = $"?culture={Uri.EscapeDataString(culture)}&" + $"redirectUri={Uri.EscapeDataString(uri)}"; + + // Redirect the user to the culture controller to set the cookie + this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true); + } + } +} \ No newline at end of file diff --git a/BlazorApp1/Shared/MainLayout.razor b/BlazorApp1/Shared/MainLayout.razor index 62f8c7a..7d9071c 100644 --- a/BlazorApp1/Shared/MainLayout.razor +++ b/BlazorApp1/Shared/MainLayout.razor @@ -10,6 +10,9 @@
About +
+ +
diff --git a/BlazorApp1/_Imports.razor b/BlazorApp1/_Imports.razor index 6ccf59e..1719665 100644 --- a/BlazorApp1/_Imports.razor +++ b/BlazorApp1/_Imports.razor @@ -8,4 +8,6 @@ @using Microsoft.JSInterop @using BlazorApp1 @using BlazorApp1.Shared -@using Blazorise.DataGrid \ No newline at end of file +@using Blazorise.DataGrid +@using Blazored.Modal +@using Blazored.Modal.Services \ No newline at end of file diff --git a/BlazorApp1/wwwroot/images/ma binocle.png b/BlazorApp1/wwwroot/images/ma binocle.png new file mode 100644 index 0000000..7402cee Binary files /dev/null and b/BlazorApp1/wwwroot/images/ma binocle.png differ