public async override Task InitializeAsync(object navigationData) { await Task.Run(() => { #if USE_SETTINGS //--- Retrieve the Selected Sow from the Global Settings // Map Dto to ViewModel //TODO: Replace property mapping with AutoMapper _selectedSowDto = GlobalSetting.Instance.CurrentSelectedSowDto; #else //--- Map the Selected Sow from the navigationData Parameter _selectedSowDto = navigationData as SowDto; #endif SowId = _selectedSowDto.Id; Name.Value = _selectedSowDto.Name; Box.Value = _selectedSowDto.Box; }); }
private async Task SelectedSowAsync(SowDto pSelectedSow) { try { if (pSelectedSow == null) { return; } await NavigationService.DisplayAlert("Sow selected", $"Sow: {pSelectedSow.Name} has been selected !", "Ok"); #if USE_SETTINGS //--- Navigation by adding the selected sow to the global settings // add the selected sow to the global settings GlobalSetting.Instance.CurrentSelectedSowDto = pSelectedSow; // navigate to the sow detail view for the selected sow await NavigationService.NavigateToAsync <SowDetailsViewModel>(); #else //--- Navigation by passing the selected sow as a parameter of the destination View-Model await NavigationService.NavigateToAsync <SowDetailsViewModel>(pSelectedSow); #endif await NavigationService.RemoveLastFromBackStackAsync(); } catch (Exception ex) { var viewModelName = this.GetType().FullName; var commandName = nameof(SelectedSowAsync); var exMessage = ex.InnerException == null?string.Format($"ErrorMessage: {ex.Message}") : string.Format($"ErrorMessage: {ex.Message}, InnerException Message: {ex.InnerException.Message}"); await NavigationService.DisplayAlert(AppResources.ErrorOccured, new ViewModelCommandExecutionException(viewModelName, commandName, exMessage).Message, "Ok"); throw ex; } }