public ActionResult <Shelvesdto> Post(string id) { var db = new DataContext(); Guid idguid = Guid.Parse(id); Bookdto book = GetBooks(idguid); if (!book.Equals(null)) { List <Shelvesdto> shelves = null; Shelvesdto shelve = new Shelvesdto(book.Id, book.Title); shelves.Add(shelve); // Create Console.WriteLine("Inserting a new book"); db.Add(shelve); db.SaveChanges(); // Read Console.WriteLine("Querying for a blog"); var Book = db.Book .OrderBy(b => b.Id) .First(); return(Ok(shelve)); } return(NotFound()); }
public IHttpActionResult GetBook(string id) { Book book = db.Books.Find(id); if (book == null) { return(NotFound()); } Bookdto bookdto = new Bookdto(); bookdto.ISBN = book.ISBN; bookdto.Price = book.Price; bookdto.Title = book.Title; bookdto.Year = book.Year; if (book.UserID != null) { bookdto.UserID = book.UserID; } return(Ok(bookdto)); }
// GET: api/Books public List <Bookdto> GetBooks() { // string Name = User.Identity.Name; // Get User Name // var Claims = ((ClaimsIdentity)(User.Identity)).Claims.ToList();// Get User ID List <Bookdto> bookListdto = new List <Bookdto>(); foreach (var item in db.Books) { Bookdto bookdto = new Bookdto(); bookdto.ISBN = item.ISBN; bookdto.Price = item.Price; bookdto.Title = item.Title; bookdto.Year = item.Year; if (item.UserID != null) { bookdto.UserID = item.UserID; } bookListdto.Add(bookdto); } return(bookListdto); }