public async Task <IHttpActionResult> PostBookshelfItem(BookshelfItem bookshelfItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (bookshelfItem.ImgURI == null) { GoogleBookSearch search = new GoogleBookSearch(); IEnumerable <Book> result = await search.GeneralSearch(bookshelfItem.ISBN); Book firstResult = result.FirstOrDefault(); if (firstResult != null) { bookshelfItem.ImgURI = firstResult.ImgURI; } } //if uri null go get if //call uri returner //bookshelfItem //web api 401 error if not logged in var userID = User.Identity.GetUserId(); string currentUserID = User.Identity.GetUserId(); ApplicationUser userFound = db.Users.Find(currentUserID); bookshelfItem.User = userFound; db.BookShelfItems.Add(bookshelfItem); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = bookshelfItem.Id }, bookshelfItem)); }
public IHttpActionResult DeleteBookshelfItem(int id) { var userID = User.Identity.GetUserId(); string currentUserID = User.Identity.GetUserId(); BookshelfItem bookshelfItem = db.BookShelfItems.Find(id); if (bookshelfItem == null) { return(NotFound()); } if (currentUserID == bookshelfItem.User.Id) { db.BookShelfItems.Remove(bookshelfItem); db.SaveChanges(); } else { return(NotFound()); } return(Ok(bookshelfItem)); }