public TruckRepairViewModel() { TruckRepair = new ObservableRangeCollection <Models.TruckRepair>(); LoadTruckRepairCommand = new Command(() => ExecuteLoadTruckRepairCommand()); DeleteCommand = new Command(() => ExecutedeleteCommand()); MessagingCenter.Subscribe <NewTruckRepairPage, TruckRepair>(this, "AddItem", async(obj, truckrepair) => { var _truckrepair = truckrepair as TruckRepair; _truckrepair.TruckID = truck.ID; TruckRepair.Add(_truckrepair); await TruckRepairStore.AddTruckRepairAsync(_truckrepair); }); }
async void ExecuteLoadTruckRepairCommand() { try { TruckRepair.Clear(); var truckrepairs = await TruckRepairStore.GetbyTruckRepairAsync(truck); TruckRepair.ReplaceRange(truckrepairs); } catch (Exception ex) { Debug.WriteLine(ex); MessagingCenter.Send(new MessagingCenterAlert { Title = "Error", Message = "Unable to load Trucks Repairs.", Cancel = "OK" }, "message"); } }
async void ExecutedeleteCommand() { await TruckRepairStore.DeleteTruckRepairAsync(truckrepair); }