/// <summary> /// Delete a NewsUser /// </summary> /// <param name="newsUser">The NewsUser to be deletedr</param> /// <returns></returns> public async Task DeleteNewsUserAsync(NewsUser newsUser) { try { #if OFFLINE_SYNC_ENABLED if (syncItems) { await this.SyncAsync(); } #endif var arguments = new Dictionary <string, string> { { "newsid", newsUser.NewsId }, { "userid", newsUser.UserId } }; await client.InvokeApiAsync("newsuser", System.Net.Http.HttpMethod.Delete, arguments); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"Sync error: {0}", e.Message); } }
public async void BookmarkAsync(News news) { try { if (User.CurrentUser.Authenticated) { // bookmark or unbookmark if the user is authenticated NewsUser newsUser = new NewsUser(news.Id, User.CurrentUser.Id); if (!User.CurrentUser.Bookmarks.Contains(news)) { await NewsManager.DefaultManager.SaveNewsUserAsync(newsUser); news.IsBookmarkedByUser = true; User.CurrentUser.Bookmarks.Add(news); } else { // remove from the database await NewsManager.DefaultManager.DeleteNewsUserAsync(newsUser); User.CurrentUser.Bookmarks.RemoveWhere((n) => n.Id == newsUser.NewsId); news.IsBookmarkedByUser = false; // remove from the Bookmarks property of CurrentUser } } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public async Task SaveNewsUserAsync(NewsUser item) { if (item.Id == null) { await NewsUserTable.InsertAsync(item); } else { await NewsUserTable.UpdateAsync(item); } }