// Add drill to database public async Task AddDrill(DrillItem drillItem, String n, int s, int t, string sty, string use) { drillItem.Name = n; drillItem.Sets = s; drillItem.SetTime = t; drillItem.Style = sty; drillItem.Use = use; await App.MobileService.GetTable <DrillItem>().InsertAsync(drillItem); drills.Add(drillItem); }
// Update drill in database public async Task UpdateDrill(String Id, String n, int s, int t, string sty, string use) { DrillItem drillItem = new DrillItem(); drillItem.Id = Id; drillItem.Name = n; drillItem.Sets = s; drillItem.SetTime = t; drillItem.Style = sty; drillItem.Use = use; await App.MobileService.GetTable <DrillItem>().UpdateAsync(drillItem); }
// Delete drill from database public async Task DeleteDrillAsync(string id) { Console.WriteLine(id); MobileServiceInvalidOperationException exception = null; DrillItem d = new DrillItem(); d.Id = id; try { await drillTable.DeleteAsync(d); } catch (MobileServiceInvalidOperationException e) { exception = e; } if (exception != null) { await new MessageDialog(exception.Message, "Error deleting item").ShowAsync(); } }
// Add a new drill to database public async void SubmitBtn_Click(object sender, RoutedEventArgs e) { // Drill variables DrillItem drillItem = new DrillItem(); String Name = (String)NameBox.Text; String Use = (String)UseCombo.SelectionBoxItem; int Sets; int Time = TimeBox.Time.Minutes; int hours = TimeBox.Time.Hours; int i = 0; // convert time for user to mins while (i <= hours) { Time = Time + 60; i += 1; } // check sets bool successfullyParsedSets = int.TryParse(SetsBox.Text, out Sets); // Check ints if (successfullyParsedSets) { Sets = Int32.Parse(SetsBox.Text); } // error checks if (Name == null) { Name = "Empty drill"; } else if (Use == null) { Use = "Empty equipment"; } try { // Call ViewModel controller to add to the Model then create the toast to inform user of add await ctv.combatDrillsTable.AddDrill(drillItem, Name, Sets, Time, catagory, Use); ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = Name + " added to " + catagory, HintStyle = AdaptiveTextStyle.Body }, new AdaptiveText() { Text = "Refresh the page to see updates!", HintWrap = true, HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }; // Show custom Toast for success var notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(new ToastNotification(content.GetXml())); } catch { ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = Name + " Failed to be added into " + catagory, HintStyle = AdaptiveTextStyle.Body }, new AdaptiveText() { Text = "Try checking your connection or trying later!", HintWrap = true, HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }; // Show custom Toast for failed var notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(new ToastNotification(content.GetXml())); } // Clean up and notify user ppup.IsOpen = false; }