@page "/fundvelo/keydata/Missing" @inherits CaritasServiceFundVeloKeyDataPageBase @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

@i18n["MissingBike"]

@if (loading) { }
@context?.Bezeichnung
@context?.Bezeichnung
@context?.Bezeichnung
@i18n["Cancel"]
@i18n["Continue"]
@code { [Parameter] public string FromRoute { get; set; } 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 string frameNumber; private string remark; private uint age; private float price; private void setBrandValue(string value) { brandStringValue = value; selectedBrand = null; } protected async override void OnInitialized() { base.OnInitialized(); await GetColors(); await GetBicycleTypes(); await GetBrands(); refreshGUIFromDto(); PageHistoryManager.AddPageToHistory(NavigationManager.Uri); 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(); NavigationManager.NavigateTo("fundvelo/account/Missing"); } private void Cancel() { NavigationManager.NavigateTo("caritas_services"); } 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() { MissingReport report = ReportDataProvider.GetMissingReport(); 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; age = report.Alter; price = report.Preis; } private void updateDtoFromGUI() { MissingReport report = ReportDataProvider.GetMissingReport(); 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.Alter = age; report.Preis = price; } }