@page "/account" @page "/fundvelo/account/{FromRoute}" @using cwebplusApp.Shared.Models; @using cwebplusApp.Shared.Services; @inject NavigationManager NavigationManager @inject UserDataProvider UserDataProvider @inject IStringLocalizer I18n @inject PageHistoryManager PageHistoryManager @inject ReportDataProvider ReportDataProvider @inject Toaster Toaster @inject InputCursorHandler InputCursorHandler @inject MasterDataService MasterDataService

@I18n["MyData"]

@I18n["Male"] @I18n["Female"]
@context?.Zip_City
@if (!string.IsNullOrEmpty(FromRoute)) {
@*
@I18n["Save"]
*@
@I18n["Cancel"]
@I18n["Send"]
} else {
@I18n["Save"]
}
@code { [Parameter] public string FromRoute { get; set; } private UserData Account = new(); private bool saveBevorSend = true; private string zipCityStringValue; private ZipCity selectedZipCity; private ZipCity SelectedZipCity { get { return selectedZipCity; } set { selectedZipCity = (value != null) ? value : new ZipCity(zipCityStringValue); } } private void setZipCityValue(string value) { zipCityStringValue = value; selectedZipCity = null; } private ZipCity[] ZipCities { get => MasterDataService.ZipCities; } protected async override void OnInitialized() { base.OnInitialized(); PageHistoryManager.OnBeforeNavigateBack = new EventCallback(this, (Action)OnBeforeNavigateBack); Account = await GetUserData(); if (!string.IsNullOrEmpty(FromRoute) && ReportDataProvider.Report != null) { UserDataProvider.MapUserData(Account, ReportDataProvider.Report); } var combinedValue = Account.Zip + " " + Account.City; setZipCityValue(combinedValue); if (ZipCities == null) SelectedZipCity = new ZipCity(combinedValue); else SelectedZipCity = Array.Find(ZipCities, zipCity => (zipCity.Zip.Equals(Account.Zip) && zipCity.City.Equals(Account.City))); StateHasChanged(); } private void OnBeforeNavigateBack() { if (ReportDataProvider.Report != null) { UserDataProvider.MapReport(ReportDataProvider.Report, Account); } } private async Task SaveUserData() { try { Account.Zip = SelectedZipCity.Zip; Account.City = SelectedZipCity.City; Validator.ValidateAccount(Account); await UserDataProvider.Save(Account); Toaster.ShowSuccess(I18n.GetString("Success.SaveUserdata.Title"), I18n.GetString("Success.SaveUserdata.Msg")); } catch (ArgumentException) { Toaster.ShowWarning(I18n.GetString("Warning.MandatoryFields.Title"), I18n.GetString("Warning.MandatoryFields.Msg")); } } private async void SaveUserDataAndClose() { try { Account.Zip = SelectedZipCity == null ? null : SelectedZipCity.Zip; Account.City = SelectedZipCity == null ? null : SelectedZipCity.City; Validator.ValidateAccount(Account); await UserDataProvider.Save(Account); Toaster.ShowSuccess(I18n.GetString("Success.SaveUserdata.Title"), I18n.GetString("Success.SaveUserdata.Msg")); NavigationManager.NavigateTo("caritas_services"); } catch (ArgumentException) { Toaster.ShowWarning(I18n.GetString("Warning.MandatoryFields.Title"), I18n.GetString("Warning.MandatoryFields.Msg")); } } private async Task GetUserData() { return await UserDataProvider.Get(); } private string getZipCityLbl() { return String.Format("{0} {1}", I18n.GetString("Zip"), I18n.GetString("City")); } private async void Next() { PageHistoryManager.AddPageToHistory(NavigationManager.Uri); try { if (!string.IsNullOrEmpty(FromRoute) && saveBevorSend) { await SaveUserData(); } if ("Found".Equals(FromRoute)) { UserDataProvider.MapReport(ReportDataProvider.Report, Account); Validator.ValidateContact(ReportDataProvider.Report); NavigationManager.NavigateTo("fundvelo/conclusion_found"); } else { UserDataProvider.MapMissingReport(ReportDataProvider.GetMissingReport(), Account); Validator.ValidateContact(ReportDataProvider.Report); NavigationManager.NavigateTo("fundvelo/conclusion_missing"); } } catch (ArgumentException) { Toaster.ShowWarning(I18n.GetString("Warning.MandatoryFields.Title"), I18n.GetString("Warning.MandatoryFields.Msg")); } } private void Cancel() { NavigationManager.NavigateTo("caritas_services"); } }