/// <summary> /// Initializes a new instance of the <see cref="ConstructorViewModel"/> class given the list of constructors to display. /// </summary> /// <param name="data">Constructor table to print.</param> /// <param name="title">Title of the content page.</param> public ConstructorViewModel(ConstructorTable data, string title) { this._constructors = data; Title = title; Items = new ObservableCollection <Constructor>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); }
/// <summary> /// Executes the load items command. /// </summary> /// <param name="origin">The origin.</param> async Task ExecuteLoadItemsCommand(string origin = "") { if (IsBusy) { return; } IsBusy = true; try { // Only if data is not provided retrieve every one. if (origin == _origin_notprovided) { _constructors = await App.RestService.GetConstructorsAsync(); } _constructors.Constructors = _constructors.Constructors.OrderBy(o => o.Name).ToList(); LoadItemsFromData(); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
/// <summary> /// Open a constructor list with that info. /// </summary> /// <param name="page">Current ContentPage.</param> /// <param name="constructors">List of constructors.</param> /// <param name="title">Title to display in the bar.</param> /// <param name="warning">Indicates if show a warning when no data is provided.</param> public static void OpenConstructor(ContentPage page, ConstructorTable constructors, string title, bool warning = true) { if (constructors != null) { page.Navigation.PushAsync(new ConstructorPage(new ConstructorViewModel(constructors, title))); } else { ShowWarning(page, warning); } }