async Task ExecLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; Stolies.Clear(); var items = await Stolyies.GetItemsAsync(true); try { foreach (var item in items) { Stolies.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public ZkouskaViewModel() { Stolies = new ObservableCollection <Models.StolyBackup>(); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = true }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = true }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = false }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 40, Obsazeno = false }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = true }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 10, Obsazeno = false }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 80, Obsazeno = false }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = true }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = false }); Stolyies.AddItemAsync(new Models.StolyBackup { Kapacita = 20, Obsazeno = false }); Polozky.AddItemAsync(new Models.Polozka { Cena = 2, Nazev = "Pivo" }); LoadItemsCommand = new Command(async() => await GetTask()); }
public StolyViewModel() { Title = "Stoly"; Stolies = new ObservableCollection <StolyBackup>(); LoadItemsCommand = new Command(async() => await ExecLoadItemsCommand()); ///Příjem zprávy MessagingCenter.Subscribe <StolyNewPage, StolyBackup>(this, "AddTable", async(obj, item) => { var newItem = item as StolyBackup; try { Stolies.Add(newItem); await Stolyies.AddItemAsync(newItem); } catch (Exception e) { Debug.WriteLine(e.Message); } }); }