- Initilization - variable handling refactoredmaster
| @@ -11,7 +11,7 @@ | |||
| @inject IStringLocalizer<Resources> i18n | |||
| @inject PageHistoryManager PageHistoryManager | |||
| @inject MasterDataService MasterDataService | |||
| @inject IMatToaster Toaster | |||
| @inject Toaster Toaster | |||
| @inject IJSRuntime JS | |||
| @@ -192,26 +192,18 @@ | |||
| } | |||
| private async Task GetColors() { | |||
| //await InvokeAsync(async () => { | |||
| // await MasterDataService.GetColors(); | |||
| // StateHasChanged(); | |||
| //}); | |||
| await MasterDataService.GetColors(); | |||
| StateHasChanged(); | |||
| } | |||
| private async Task GetBicycleTypes() { | |||
| await InvokeAsync(async () => { | |||
| await MasterDataService.GetBicycleTypes(); | |||
| StateHasChanged(); | |||
| }); | |||
| await MasterDataService.GetBicycleTypes(); | |||
| StateHasChanged(); | |||
| } | |||
| private async Task GetBrands() { | |||
| await InvokeAsync(async () => { | |||
| await MasterDataService.GetBrands(); | |||
| StateHasChanged(); | |||
| }); | |||
| await MasterDataService.GetBrands(); | |||
| StateHasChanged(); | |||
| } | |||
| private ColorItem[] Colors { | |||
| @@ -258,9 +250,9 @@ | |||
| } catch (IOException ex) { | |||
| Console.WriteLine("Ex.Message is: {0}.", ex.Message); | |||
| if (ex.Message.Contains("exceeds the maximum of")) { | |||
| Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024))); | |||
| Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024))); | |||
| } else { | |||
| Show(MatToastType.Danger, i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg")); | |||
| Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg")); | |||
| } | |||
| } catch (JSException ex) { | |||
| Console.WriteLine("Ex.Message is: {0}.", ex.Message); | |||
| @@ -31,7 +31,7 @@ namespace CaritasPWA.Pages { | |||
| private BlazorGeolocationService BlazorGeolocationService { get; init; } | |||
| [Inject] | |||
| private MatBlazor.IMatToaster Toaster { get; init; } | |||
| private Toaster Toaster { get; init; } | |||
| [Inject] | |||
| private IStringLocalizer<Resources> I18n { get; init; } | |||
| @@ -59,10 +59,6 @@ namespace CaritasPWA.Pages { | |||
| this.NominatimService = new NominatimService(); | |||
| } | |||
| protected void Show(MatBlazor.MatToastType type, string title, string message, string icon = "") { | |||
| Toaster.Add(message, type, title, icon); | |||
| } | |||
| protected async Task AddEventsToMap() { | |||
| await this.mapRef.OnClick(async (MouseEvent mouseEvent) => await OnMouseMapClicked(mouseEvent)); | |||
| } | |||
| @@ -89,7 +85,7 @@ namespace CaritasPWA.Pages { | |||
| private async Task ShowDeviceGeoLocation() { | |||
| BlazorGeolocationPosition position = await this.BlazorGeolocationService.GetPositionAsync(); | |||
| if (position.ErrorCode != null) { | |||
| Show(MatBlazor.MatToastType.Danger, I18n.GetString("Error.GeoLocation.Title", position.ErrorCode), I18n.GetString("Error.GeoLocation.Msg", position.ErrorMessage)); | |||
| Toaster.ShowError(I18n.GetString("Error.GeoLocation.Title", position.ErrorCode), I18n.GetString("Error.GeoLocation.Msg", position.ErrorMessage)); | |||
| } else { | |||
| LatLng geoPosition = new((double)position.Latitude, (double)position.Longitude); | |||
| @@ -114,7 +110,7 @@ namespace CaritasPWA.Pages { | |||
| this.bicycleGeoPosition.Address = GetFormattedAddressStreet(addressDto); | |||
| this.bicycleGeoPosition.City = GetFormattedAddressZipAndTown(addressDto); | |||
| } else { | |||
| Show(MatBlazor.MatToastType.Warning, I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | |||
| Toaster.ShowWarning(I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | |||
| } | |||
| StateHasChanged(); | |||
| @@ -5,6 +5,7 @@ | |||
| @inject IStringLocalizer<Resources> i18n | |||
| @inject PageHistoryManager PageHistoryManager | |||
| @inject MasterDataService MasterDataService; | |||
| @inject Toaster Toaster; | |||
| <div class="row h-100 justify-content-center"> | |||
| @@ -22,10 +23,10 @@ | |||
| </div> | |||
| <div class="row align-items-center justify-content-center vw-100 h-25"> | |||
| <div> | |||
| @if(showProgressCircle) { | |||
| @if (showProgressCircle) { | |||
| <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" Style="padding-left:1.2rem" /> | |||
| <h6 style="font-style:italic;padding-bottom:1em">@i18n["Initializing..."]</h6> | |||
| } | |||
| <h6 style="font-style:italic;padding-bottom:1em">@i18n["Info.Masterdata.Initializing"]</h6> | |||
| } | |||
| </div> | |||
| </div> | |||
| </div> | |||
| @@ -42,15 +43,21 @@ | |||
| Console.WriteLine("First activation"); | |||
| showProgressCircle = true; | |||
| StateHasChanged(); | |||
| await MasterDataService.SynchronizeMasterdata(); | |||
| showProgressCircle = false; | |||
| //await MasterDataService.SynchronizeMasterdata(); | |||
| //showProgressCircle = false; | |||
| try { | |||
| await MasterDataService.SynchronizeMasterdata(); | |||
| } catch (Exception ex) { | |||
| Toaster.ShowWarning(i18n.GetString("Warning.Masterdata.Title"), i18n.GetString("Warning.Masterdata.Msg")); | |||
| } finally { | |||
| showProgressCircle = false; | |||
| } | |||
| } | |||
| btnDisabled = false; | |||
| PageHistoryManager.Reset(); | |||
| StateHasChanged(); | |||
| } | |||
| private void ButtonClicked() { | |||
| NavigationManager.NavigateTo("./caritas_services"); | |||
| AppState.LoggedIn = true; | |||
| @@ -20,11 +20,12 @@ namespace CaritasPWA { | |||
| builder.Services.AddSingleton<ILFBicycleRest, LFBicycleRest>(); | |||
| builder.Services.AddSingleton<AppState>(); | |||
| builder.Services.AddSingleton<PageHistoryManager>(); | |||
| builder.Services.AddScoped<Toaster>(); | |||
| builder.Services.AddScoped<UserDataProvider>(); | |||
| builder.Services.AddScoped<MasterDataService>(); | |||
| builder.Services.AddScoped<BlazorGeolocationService>(); | |||
| builder.Services.AddLocalization(); | |||
| builder.Services.AddBlazorLeafletMaps(); | |||
| builder.Services.AddScoped<BlazorGeolocationService>(); | |||
| builder.Services.AddMatToaster(config => { | |||
| config.Position = MatToastPosition.BottomCenter; | |||
| @@ -315,6 +315,9 @@ | |||
| <data name="info" xml:space="preserve"> | |||
| <value>Info</value> | |||
| </data> | |||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||
| <value>Am Initialisieren...</value> | |||
| </data> | |||
| <data name="Lastname" xml:space="preserve"> | |||
| <value>Nachname</value> | |||
| </data> | |||
| @@ -372,6 +375,12 @@ | |||
| <data name="Username" xml:space="preserve"> | |||
| <value>Benutzername oder E-Mail</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||
| <value>Die Stammdaten konnten nicht abgerufen werden. Es werden stattdessen die Standardwerte verwendet!</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||
| <value>Die Stammdaten konnten nicht abgerufen werden!</value> | |||
| </data> | |||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | |||
| <value>Die Adresse konnte beim Aufrufen des Nominatim-Dienstes nicht aufgelöst werden. Bitte geben Sie die Straße und Postleitzahl/Ort manuell ein.</value> | |||
| </data> | |||
| @@ -315,6 +315,9 @@ | |||
| <data name="info" xml:space="preserve"> | |||
| <value>Information</value> | |||
| </data> | |||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||
| <value>Initialisation...</value> | |||
| </data> | |||
| <data name="Lastname" xml:space="preserve"> | |||
| <value>Nom de famille</value> | |||
| </data> | |||
| @@ -372,6 +375,12 @@ | |||
| <data name="Username" xml:space="preserve"> | |||
| <value>Nom d'utilisateur ou courriel</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||
| <value>Les données de base n'ont pas pu être récupérées. Les valeurs par défaut sont utilisées à la place !</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||
| <value>Impossible de récupérer les données de base !</value> | |||
| </data> | |||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | |||
| <value>L'adresse n'a pas pu être résolue en invoquant le service Nominatim. Veuillez saisir l'adresse en indiquant la rue et le code postal/ville.</value> | |||
| </data> | |||
| @@ -315,6 +315,9 @@ | |||
| <data name="info" xml:space="preserve"> | |||
| <value>Informazione</value> | |||
| </data> | |||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||
| <value>Inizializzazione...</value> | |||
| </data> | |||
| <data name="Lastname" xml:space="preserve"> | |||
| <value>Cognome</value> | |||
| </data> | |||
| @@ -372,6 +375,12 @@ | |||
| <data name="Username" xml:space="preserve"> | |||
| <value>Nome d'utente o e-mail</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||
| <value>Non è stato possibile recuperare i dati anagrafici. Vengono invece utilizzati i valori di default!</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||
| <value>Impossibile recuperare i dati anagrafici!</value> | |||
| </data> | |||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | |||
| <value>L'indirizzo non può essere risolto invocando il servizio Nominatim. Si prega di digitare la via e CAP/città.</value> | |||
| </data> | |||
| @@ -315,6 +315,9 @@ | |||
| <data name="info" xml:space="preserve"> | |||
| <value>Info</value> | |||
| </data> | |||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||
| <value>Initializing...</value> | |||
| </data> | |||
| <data name="Lastname" xml:space="preserve"> | |||
| <value>Last name</value> | |||
| </data> | |||
| @@ -372,6 +375,12 @@ | |||
| <data name="Username" xml:space="preserve"> | |||
| <value>Username or E-Mail</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||
| <value>The master data could not be retrieved. The default values are used instead!</value> | |||
| </data> | |||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||
| <value>Could not retreive master data!</value> | |||
| </data> | |||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | |||
| <value>The address could not be resolved invoking Nominatim service. Please type in the address street and zip/town.</value> | |||
| </data> | |||
| @@ -7,8 +7,8 @@ namespace CaritasPWA.Shared.Services { | |||
| Task<List<ColorItem>> GetColors(); | |||
| List<BicycleType> GetBicycleTypes(); | |||
| Task<List<BicycleType>> GetBicycleTypes(); | |||
| List<Brand> GetBrands(); | |||
| Task<List<Brand>> GetBrands(); | |||
| } | |||
| } | |||
| @@ -1,7 +1,5 @@ | |||
| using CaritasPWA.Shared.Models; | |||
| using CaritasPWA.Shared.ResourceFiles; | |||
| using Json.Net; | |||
| using Microsoft.Extensions.Localization; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Globalization; | |||
| @@ -10,44 +8,45 @@ using System.Threading.Tasks; | |||
| namespace CaritasPWA.Shared.Services { | |||
| // REST interface responsible to submit lost or found reports and get the available masterdata. | |||
| // REST interface responsible to submit lost or found reports and get the available master data. | |||
| public class LFBicycleRest : ILFBicycleRest { | |||
| private static readonly string VERSION = "v1"; | |||
| private readonly IStringLocalizer<Resources> _i18n; | |||
| private readonly HttpClient httpClient; | |||
| public LFBicycleRest(IStringLocalizer<Resources> i18n) { | |||
| _i18n = i18n; | |||
| public LFBicycleRest() { | |||
| this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") }; | |||
| } | |||
| public async Task<List<ColorItem>> GetColors() { | |||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||
| try { | |||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||
| ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync()); | |||
| return new List<ColorItem>(colors); | |||
| } | |||
| // TODO: show a warning message here | |||
| } catch (Exception ex) { | |||
| // TODO: show a warning message here | |||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||
| ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync()); | |||
| return new List<ColorItem>(colors); | |||
| } | |||
| return new List<ColorItem>(); | |||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||
| } | |||
| public List<BicycleType> GetBicycleTypes() { | |||
| //return Defaults.GetBicycleTypeDefaults(_i18n); | |||
| return new List<BicycleType>(); | |||
| public async Task<List<BicycleType>> GetBicycleTypes() { | |||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/types", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||
| BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync()); | |||
| return new List<BicycleType>(bicycleTypes); | |||
| } | |||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||
| } | |||
| public async Task<List<Brand>> GetBrands() { | |||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/brands", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||
| public List<Brand> GetBrands() { | |||
| //return Defaults.Brands.ToList(); | |||
| return new List<Brand>(); | |||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||
| Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync()); | |||
| return new List<Brand>(brands); | |||
| } | |||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||
| } | |||
| } | |||
| @@ -29,17 +29,14 @@ namespace CaritasPWA.Shared.Services { | |||
| public ColorItem[] Colors { | |||
| get => _colors; | |||
| set => _colors = value; | |||
| } | |||
| public BicycleType[] BicycleTypes { | |||
| get => _bicycleTypes; | |||
| set => _bicycleTypes = value; | |||
| } | |||
| public Brand[] Brands { | |||
| get => _brands; | |||
| set => _brands = value; | |||
| } | |||
| public event EventHandler Changed; | |||
| @@ -49,54 +46,70 @@ namespace CaritasPWA.Shared.Services { | |||
| _lFBicycleRest = lFBicycleRest; | |||
| _i18n = i18n; | |||
| _firstActivation = true; | |||
| _brands = Defaults.GetBrandDefaults(_i18n).ToArray(); | |||
| _colors = Defaults.GetColorDefaults(_i18n).ToArray(); | |||
| _bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | |||
| Console.WriteLine("MasterDataService constructor / colors: " + _colors.Length); | |||
| } | |||
| public async Task SynchronizeMasterdata() { | |||
| await SynchronizeColors(); | |||
| await SynchronizeBcTypes(); | |||
| await SynchronizeBrands(); | |||
| _firstActivation = false; | |||
| try { | |||
| await SynchronizeColors(); | |||
| await SynchronizeBcTypes(); | |||
| await SynchronizeBrands(); | |||
| } finally { | |||
| _firstActivation = false; | |||
| } | |||
| } | |||
| public async Task SynchronizeColors() { | |||
| Colors = (await _lFBicycleRest.GetColors()).ToArray(); | |||
| if (Colors != null && Colors.Length > 0) { | |||
| await SaveColorsToStorage(); | |||
| ColorItem[] colors = (await _lFBicycleRest.GetColors()).ToArray(); | |||
| if (colors != null && colors.Length > 0) { | |||
| _colors = colors; | |||
| await SaveColorsToStorage(colors); | |||
| }; | |||
| } | |||
| public async Task SynchronizeBcTypes() { | |||
| BicycleTypes = _lFBicycleRest.GetBicycleTypes().ToArray(); | |||
| if (BicycleTypes != null && BicycleTypes.Length > 0) { | |||
| await SaveBcTypesToStorage(); | |||
| BicycleType[] bicycleTypes = (await _lFBicycleRest.GetBicycleTypes()).ToArray(); | |||
| if (bicycleTypes != null && bicycleTypes.Length > 0) { | |||
| _bicycleTypes = bicycleTypes; | |||
| await SaveBcTypesToStorage(bicycleTypes); | |||
| } | |||
| } | |||
| public async Task SynchronizeBrands() { | |||
| Brands = _lFBicycleRest.GetBrands().ToArray(); | |||
| if (Brands != null && Brands.Length > 0) { | |||
| await SaveBrandsToStorage(); | |||
| Brand[] brands = (await _lFBicycleRest.GetBrands()).ToArray(); | |||
| if (brands != null && brands.Length > 0) { | |||
| _brands = brands; | |||
| await SaveBrandsToStorage(brands); | |||
| } | |||
| } | |||
| public async Task<ColorItem[]> GetColors() { | |||
| ColorItem[] colors = await GetColorsFromStorage(); | |||
| Colors = (colors != null && colors.Length > 0) ? colors: Defaults.GetColorDefaults(_i18n).ToArray(); | |||
| Colors = SortColors(new List<ColorItem>(Colors)).ToArray(); | |||
| if (colors != null && colors.Length > 0) { | |||
| _colors = colors; | |||
| } | |||
| _colors = SortColors(new List<ColorItem>(_colors)).ToArray(); | |||
| return Colors; | |||
| } | |||
| public async Task<BicycleType[]> GetBicycleTypes() { | |||
| BicycleType[] bicycleTypes = await GetBicycleTypesFromStorage(); | |||
| BicycleTypes = (bicycleTypes != null && bicycleTypes.Length > 0) ? bicycleTypes : Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | |||
| BicycleTypes = SortBicycleTypes(new List<BicycleType>(BicycleTypes)).ToArray(); | |||
| if (bicycleTypes != null && bicycleTypes.Length > 0) { | |||
| _bicycleTypes = bicycleTypes; | |||
| } | |||
| _bicycleTypes = SortBicycleTypes(new List<BicycleType>(_bicycleTypes)).ToArray(); | |||
| return BicycleTypes; | |||
| } | |||
| public async Task<Brand[]> GetBrands() { | |||
| Brand[] brands = await GetBrandsFromStorage(); | |||
| Brands = (brands != null && brands.Length > 0) ? brands : Defaults.GetBrandDefaults(_i18n).ToArray(); | |||
| Brands = SortBrands(new List<Brand>(Brands)).ToArray(); | |||
| if (brands != null && brands.Length > 0) { | |||
| _brands = brands; | |||
| } | |||
| _brands = SortBrands(new List<Brand>(_brands)).ToArray(); | |||
| return Brands; | |||
| } | |||
| @@ -132,7 +145,6 @@ namespace CaritasPWA.Shared.Services { | |||
| } else { | |||
| result = JsonNet.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>(); | |||
| } | |||
| _colors = result; | |||
| return result; | |||
| } | |||
| @@ -150,12 +162,11 @@ namespace CaritasPWA.Shared.Services { | |||
| // Read the JSON string that contains the data from the local storage | |||
| BicycleType[] result; | |||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | |||
| if (str != null) { | |||
| result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||
| } else { | |||
| if (String.IsNullOrEmpty(str)) { | |||
| result = Array.Empty<BicycleType>(); | |||
| } else { | |||
| result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||
| } | |||
| _bicycleTypes = result; | |||
| return result; | |||
| } | |||
| @@ -173,28 +184,27 @@ namespace CaritasPWA.Shared.Services { | |||
| // Read the JSON string that contains the data from the local storage | |||
| Brand[] result; | |||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBrands); | |||
| if (str != null) { | |||
| result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||
| } else { | |||
| if (String.IsNullOrEmpty(str)) { | |||
| result = Array.Empty<Brand>(); | |||
| } else { | |||
| result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||
| } | |||
| _brands = result; | |||
| return result; | |||
| } | |||
| private async Task SaveColorsToStorage() { | |||
| var json = JsonNet.Serialize(_colors); | |||
| private async Task SaveColorsToStorage(ColorItem[] colors) { | |||
| var json = JsonNet.Serialize(colors); | |||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | |||
| } | |||
| private async Task SaveBcTypesToStorage() { | |||
| var json = JsonNet.Serialize(_bicycleTypes); | |||
| private async Task SaveBcTypesToStorage(BicycleType[] bicycleTypes) { | |||
| var json = JsonNet.Serialize(bicycleTypes); | |||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); | |||
| } | |||
| private async Task SaveBrandsToStorage() { | |||
| var json = JsonNet.Serialize(_brands); | |||
| private async Task SaveBrandsToStorage(Brand[] brands) { | |||
| var json = JsonNet.Serialize(brands); | |||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| using MatBlazor; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Threading.Tasks; | |||
| namespace CaritasPWA.Shared.Services { | |||
| public class Toaster { | |||
| private readonly IMatToaster matToaster; | |||
| public Toaster(IMatToaster toaster) { | |||
| this.matToaster = toaster; | |||
| } | |||
| public void ShowInfo(string title, string message, string icon = "") { | |||
| matToaster.Add(message, MatBlazor.MatToastType.Info, title, icon); | |||
| } | |||
| public void ShowWarning(string title, string message, string icon = "") { | |||
| matToaster.Add(message, MatBlazor.MatToastType.Warning, title, icon); | |||
| } | |||
| public void ShowError(string title, string message, string icon = "") { | |||
| matToaster.Add(message, MatBlazor.MatToastType.Danger, title, icon); | |||
| } | |||
| } | |||
| } | |||