Esempio n. 1
0
        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()));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public IQueryable<SelectedBook> GetBooks(RavenId<Profile> id)
 {
     var profile = Docs.Load<Profile>(id.ToString());
     return profile.ReadingList.AsQueryable();
 }
Esempio n. 5
0
 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()));
 }