@page "/fundvelo/keydata/Found" @inherits CaritasServiceFundVeloKeyDataPageBase @implements IDisposable; @using cwebplusApp.Shared.Models; @using cwebplusApp.Shared.Services; @using System.Globalization; @using Microsoft.AspNetCore.Components.Forms; @using System.IO; @inject NavigationManager NavigationManager @inject IStringLocalizer i18n @inject PageHistoryManager PageHistoryManager @inject MasterDataService MasterDataService @inject Toaster Toaster @inject IJSRuntime JS @inject ReportDataProvider ReportDataProvider @inject OnlineStatusProvider OnlineStatusProvider

@i18n["FoundBike"]

@if (loading) { }
@if (OnlineStatusProvider.Online) {
}
@context?.Bezeichnung
@context?.Bezeichnung
@context?.Bezeichnung
@i18n["Cancel"]
@i18n["Continue"]
@code { private static long MAX_FILE_SIZE = 3145728; //3MB private string imgUrl = string.Empty; private Boolean loading = false; private ColorItem selectedColor; private BicycleType selectedBcType; private string brandStringValue; private Brand selectedBrand; private Brand SelectedBrand { get { return selectedBrand; } set { selectedBrand = (value != null) ? value : new Brand(-999, brandStringValue); } } private void setBrandValue(string value) { brandStringValue = value; selectedBrand = null; } private string frameNumber; private string remark; private bool abholadresseIsNotContact; public void Dispose() { OnlineStatusProvider.RemoveOnlineStatusChangeCallBack(OnOnlineStatusChanged); } protected async override void OnInitialized() { base.OnInitialized(); await GetColors(); await GetBicycleTypes(); await GetBrands(); refreshGUIFromDto(); PageHistoryManager.AddPageToHistory(NavigationManager.Uri); OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged); StateHasChanged(); } private void OnOnlineStatusChanged(bool isOnline) { StateHasChanged(); } private async void AfterRenderMap() { FoundReport report = ReportDataProvider.GetFoundReport(); if (report.GeographicInfo.Latitude != 0 && report.GeographicInfo.Longitude != 0) { bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider); LatLng coordinates = new LatLng(report.GeographicInfo.Latitude, report.GeographicInfo.Longitude); MouseEvent mouseEvent = new MouseEvent(); mouseEvent.LatLng = coordinates; await InitializeMapPosition(); await AddBicycleMarkerOnClickPosition(mouseEvent); StateHasChanged(); } } private Brand getBrand(Brand brand) { return brand != null ? brand : new Brand(-999, "Test"); } private async Task GetColors() { await MasterDataService.GetColors(); } private async Task GetBicycleTypes() { await MasterDataService.GetBicycleTypes(); } private async Task GetBrands() { await MasterDataService.GetBrands(); } private ColorItem[] Colors { get => MasterDataService.Colors; } private BicycleType[] BicycleTypes { get => MasterDataService.BicycleTypes; } private Brand[] Brands { get => MasterDataService.Brands; } private void Next() { updateDtoFromGUI(); if (abholadresseIsNotContact) { NavigationManager.NavigateTo("fundvelo/alternate_pickup"); } else { NavigationManager.NavigateTo("fundvelo/account/Found"); } } private void Cancel() { NavigationManager.NavigateTo("caritas_services"); } private string getAddressLbl() { return i18n.GetString("Address") + " (" + i18n.GetString("PlaceOfDiscovery") + ")"; } private async Task OnGatheringPicture(InputFileChangeEventArgs e) { IBrowserFile imgFile = e.File; var buffer = new byte[imgFile.Size]; imgUrl = string.Empty; loading = true; StateHasChanged(); try { using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) { await stream.ReadAsync(buffer); imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}"; await stream.DisposeAsync(); } } catch (IOException ex) { Console.WriteLine("Ex.Message is: {0}.", ex.Message); if (ex.Message.Contains("exceeds the maximum of")) { Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024))); } else { Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg")); } } catch (JSException ex) { Console.WriteLine("Ex.Message is: {0}.", ex.Message); } finally { Array.Clear(buffer, 0, buffer.Length); buffer = null; loading = false; StateHasChanged(); } } private void refreshGUIFromDto() { FoundReport report = ReportDataProvider.GetFoundReport(); bicycleGeoPosition.Address = report.GeographicInfo.Address; bicycleGeoPosition.Zip = report.GeographicInfo.Postcode; bicycleGeoPosition.City = report.GeographicInfo.Town; bicycleGeoPosition.Latitude = report.GeographicInfo.Latitude; bicycleGeoPosition.Longitude = report.GeographicInfo.Longitude; imgUrl = report.FotoString; selectedColor = Array.Find(Colors, color => color.Id == report.FarbeId); selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke); selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId); frameNumber = report.RahmenNummer; remark = report.Bemerkung; abholadresseIsNotContact = !report.AbholadresseIstKontakt; } private void updateDtoFromGUI() { FoundReport report = ReportDataProvider.GetFoundReport(); report.GeographicInfo.Address = bicycleGeoPosition.Address; report.GeographicInfo.Postcode = bicycleGeoPosition.Zip; report.GeographicInfo.Town = bicycleGeoPosition.City; report.GeographicInfo.Latitude = bicycleGeoPosition.Latitude; report.GeographicInfo.Longitude = bicycleGeoPosition.Longitude; report.FotoString = imgUrl; report.FarbeId = selectedColor != null ? selectedColor.Id : null; report.TypId = selectedBcType != null ? selectedBcType.Id : null; if (SelectedBrand != null) { if (SelectedBrand.Id == -999) { report.NeueMarke = SelectedBrand.Bezeichnung; } else { report.MarkeId = SelectedBrand.Id; } } report.RahmenNummer = frameNumber; report.Bemerkung = remark; report.AbholadresseIstKontakt = !abholadresseIsNotContact; } }