Exemplo n.º 1
0
        public IHttpActionResult PutTitles(string id, Titles titles)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != titles.ISBN)
            {
                return(BadRequest());
            }

            db.Entry(titles).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TitlesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutAuthors(int id, Authors authors)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != authors.AuthorID)
            {
                return(BadRequest());
            }

            db.Entry(authors).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public Book UpdateBook(Book b)
        {
            Book updateBook;

            using (BooksDB entities = new BooksDB())
            {
                try
                {
                    updateBook            = entities.Books.Find(b.BookID);
                    updateBook.Author     = b.Author;
                    updateBook.ISBN       = b.ISBN;
                    updateBook.Price      = b.Price;
                    updateBook.Stock      = b.Stock;
                    updateBook.Title      = b.Title;
                    updateBook.CategoryID = b.CategoryID;
                    entities.SaveChanges();
                }
                catch (Exception e)
                {
                    return(b);
                }
            }
            return(updateBook);
        }