/// <summary> /// Saves an calendar entry to the database asyncronously /// </summary> /// <param name="entry">The calendar entry to store</param> /// <returns>An integer indicating the primary key of the calendar entry</returns> public async Task <int> SaveCalendarEntryAsync(RecipeCalendarEntry entry) { if (CalendarList != null && CalendarList.Any(e => e.Id == entry.Id)) { return(await _database.UpdateAsync(entry)); } else if (entry.Id != 0) { return(await _database.InsertOrReplaceAsync(entry)); } else { return(await _database.InsertAsync(entry)); } }
/// <summary> /// Catches the event when the time is set /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The arguments</param> private void OnTimeSet(object sender, TimeSetEventArgs e) { string[] datetime = ItemParser.ParseDateTimeForEntry(saveDate, e.HourOfDay, e.Minute); string date = datetime[0]; string time = datetime[1]; if (!string.IsNullOrWhiteSpace(time) && !string.IsNullOrWhiteSpace(date)) { RecipeCalendarEntry entry = new RecipeCalendarEntry(); entry.RecipeId = calendarRecipe.Id; entry.Time = time; entry.Date = date; CalendarFragment.ViewModel.AddCalendarEntryCommand.Execute(entry); calendarRecipe.CanDelete = false; Log.Debug("DateTime", date + time); } }
/// <summary> /// Handles the actions when an adapter item is longclicked /// </summary> /// <param name="sender">the adapter item</param> /// <param name="e">the event args</param> private void Adapter_ItemLongClick(object sender, RecyclerClickEventArgs e) { RecipeCalendarEntry entry = ViewModel.Calendar[selectedItem]; AlertDialog.Builder confirmAlert = new AlertDialog.Builder(this.Activity); confirmAlert.SetTitle(BrowseRecipeFragment.ViewModel.Recipes[entry.RecipeId].Name); confirmAlert.SetMessage(GetString(Resource.String.calendar_confirmDelete)); confirmAlert.SetPositiveButton(GetString(Resource.String.yes), (senderFromAlert, args) => { selectedItem = e.Position; ViewModel.DeleteCalendarEntryCommand.Execute(entry); adapter.ShownEntries.Remove(entry); adapter.NotifyItemRemoved(selectedItem); }); Dialog dialog = confirmAlert.Create(); dialog.Show(); }
/// <summary> /// Updates an ingredient /// </summary> /// <param name="ingredient">>the ingredient to update</param> /// <returns>the task</returns> async Task UpdateCalendarEntry(RecipeCalendarEntry entry) { RecipeCalendarEntry _entry = null; foreach (RecipeCalendarEntry cal in Calendar) { if (cal.Id == entry.Id) { _entry = cal; break; } } if (_entry != null) { Calendar.Remove(_entry); Calendar.Add(entry); await CalendarDataStore.UpdateItemAsync(entry); } }
/// <summary> /// Deletes a calendar entry from the database asyncronously /// </summary> /// <param name="entry">The calendar entry to delete</param> /// <returns>An integer indicating the deleted id</returns> public async Task <int> DeleteCalendarEntryAsync(RecipeCalendarEntry entry) { CalendarList.Remove(entry); return(await _database.DeleteAsync <RecipeCalendarEntry>(entry.Id)); }
/// <summary> /// Deletes a calendar entry /// </summary> /// <param name="entry">>the entry to delete</param> /// <returns>the task</returns> async Task DeleteCalendarEntry(RecipeCalendarEntry entry) { Calendar.Remove(entry); await CalendarDataStore.DeleteItemAsync(entry.Id); }
/// <summary> /// Adds a calendar entry /// </summary> /// <param name="entry">the calendar entry to add</param> /// <returns>the task</returns> async Task AddCalendarEntry(RecipeCalendarEntry entry) { Calendar.Add(entry); await CalendarDataStore.AddItemAsync(entry); }