public HttpResponseMessage<SelectedBook> GetBook(RavenId<Profile> id, RavenId<Book> bookId) { var profile = Docs.Load<Profile>(id.ToString()); if (profile == null) return new HttpResponseMessage<SelectedBook>(HttpStatusCode.NotFound); return new HttpResponseMessage<SelectedBook>(profile.ReadingList.SingleOrDefault(b => b.Id == bookId.ToString())); }
public HttpResponseMessage RemoveBook(RavenId<Profile> id, RavenId<Book> bookId) { var profile = Docs.Load<Profile>(id.ToString()); if (profile == null) return new HttpResponseMessage(HttpStatusCode.NotFound); var selectedBook = profile.ReadingList.SingleOrDefault(b => b.Id == bookId.ToString()); if (selectedBook != null) { profile.ReadingList.Remove(selectedBook); } return new HttpResponseMessage(HttpStatusCode.OK); }
public HttpResponseMessage<SelectedBook> UpdateBook(RavenId<Profile> id, RavenId<Book> bookId, int rating = 0) { var profile = Docs.Load<Profile>(id.ToString()); if (profile == null) return new HttpResponseMessage<SelectedBook>(HttpStatusCode.NotFound); var book = Docs.Load<Book>(bookId.ToString()); if (book == null) return new HttpResponseMessage<SelectedBook>(HttpStatusCode.NotFound); var selectedBook = profile.ReadingList.SingleOrDefault(b => b.Id == bookId.ToString()); if (selectedBook == null) { selectedBook = new SelectedBook { Id = book.Id, Title = book.Title }; profile.ReadingList.Add(selectedBook); } selectedBook.Rating = NormalizeRating(rating); return new HttpResponseMessage<SelectedBook>(selectedBook, HttpStatusCode.OK); }
public IQueryable<SelectedBook> GetBooks(RavenId<Profile> id) { var profile = Docs.Load<Profile>(id.ToString()); return profile.ReadingList.AsQueryable(); }
public HttpResponseMessage<Profile> Get(RavenId<Profile> id) { return id.ToString() != GetUser().Id ? new HttpResponseMessage<Profile>(HttpStatusCode.Forbidden) : new HttpResponseMessage<Profile>(Docs.Load<Profile>(id.ToString())); }