public Task UnlikeBookAsync() { if (bookReading == null) { //this could happen if the book was already liked from before return IsCollectedAsync().ContinueWith(isCollected => { if (isCollected.Result) { bookReading = AppContext.CurrentUser.GetReadingForBook(SelectedBook.Id); client.Readings.DeleteReadingAsync( AppContext.AccessToken.Token, bookReading.Id).Wait(); AppContext.CurrentUser.RemoveBookFromLocalCollection(SelectedBook.Id); } else { throw new InvalidOperationException(AppStrings.NoReadingEx); } }); } else { return client.Readings.DeleteReadingAsync( AppContext.AccessToken.Token, bookReading.Id).ContinueWith(task => { if(task.IsCompleted) AppContext.CurrentUser.RemoveBookFromLocalCollection(SelectedBook.Id); }); } }
public Task LikeBookAsync() { //if reading already exists, update? return IsCollectedAsync().ContinueWith(isCollected => { if (!isCollected.Result) { string readingLink = client.Books.PostBookReadingAsync( AppContext.AccessToken.Token, SelectedBook.Id, Reading.ReadingState.Interesting).Result; AppContext.CurrentUser.AddBookToLocalCollection(SelectedBook); bookReading = client.Readings.GetFromPermalinkAsync<Reading>( readingLink, AppContext.AccessToken.Token).Result; } }); }
public Task<string> PostBookReadingAsync(string accessToken, string bookId, Reading.ReadingState state, bool isPrivate = false, string closingRemark = null) { ReadingPost newReading= new ReadingPost(); //newReading.AccessToken = accessToken; newReading.Reading = new Reading(); newReading.Reading.State = state; newReading.Reading.IsPrivate = isPrivate; newReading.Reading.ClosingRemark = closingRemark; IDictionary<string, string> parameters = GetInitializedParameterCollection(); parameters.Add(ReadmillConstants.AccessToken, accessToken); parameters.Add(BooksClient.BookId, bookId); var bookReadingUrl = booksUriTemplates[BooksUriTemplateType.BookReadings].BindByName(this.readmillBaseUri, parameters); return PostAsync<ReadingPost>(newReading, bookReadingUrl); }