コード例 #1
0
        public IHttpActionResult PutAuthor(int id, Author author)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public IHttpActionResult PutBook(Guid id, Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.GUID)
            {
                return(BadRequest());
            }

            book.UpdatedAt       = DateTime.Now;
            db.Entry(book).State = EntityState.Modified;

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

            return(Ok(0));
        }
コード例 #3
0
        public IHttpActionResult PutTitle(string id, Title title)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "AuthorID,FirstName,LastName")] Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "BookID,Title,Author,Publisher,PageNumber")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "ISBN,Title1,EditionNumber,Copyright")] Title title)
 {
     if (ModelState.IsValid)
     {
         db.Entry(title).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(title));
 }
コード例 #7
0
ファイル: BookController.cs プロジェクト: Andrashkojv/P4_lab2
 //метод  редагування інформації книги.
 //[FromBody]  - інформація про книгу передається в тілі запиту
 public IHttpActionResult Patch(int Id, [FromBody] Book book)
 {
     // спробувати оновити інформацію про книгу
     try
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(Ok(book));
     }
     // якщо трапиться помилка - повернути Internal Server Error
     catch (Exception error)
     {
         return(InternalServerError(error));
     }
 }
コード例 #8
0
 public void Remove(int id)
 {
     using (var context = new BooksEntities())
     {
         var bookToRemove = context.Books.SingleOrDefault(b => b.ID == id);
         if (bookToRemove != null)
         {
             context.Entry(bookToRemove).State = EntityState.Deleted;
             context.SaveChanges();
         }
         else
         {
             throw new DBConcurrencyException();
         }
     }
 }
コード例 #9
0
        public void EditBookById(Book book)
        {
            if (!ModelState.IsValid)
            {
                return;
            }
            var fbook = db.Books.FirstOrDefault(m => m.BookId == book.BookId);

            if (fbook == null)
            {
                throw new ArgumentNullException(nameof(fbook));
            }
            db.Entry(fbook).CurrentValues.SetValues(book);
            db.SaveChangesAsync();
            Response.Write("Succesfully updated data....");
        }
コード例 #10
0
 public void UpdateUser(Users user)
 {
     context.Entry(user).State = EntityState.Modified;
 }
コード例 #11
0
 public void UpdateBook(Book book)
 {
     context.Entry(book).State = EntityState.Modified;
 }
コード例 #12
0
        public IHttpActionResult Delete(int id)
        {
            bool selll = false;

            if (id <= 0)
            {
                return(BadRequest("Not a valid Book id"));
            }
            var selby = (from i in db.Seller_Buyer_Book
                         select i.Book_Id).ToList();

            foreach (var item in selby)
            {
                if (item == id)
                {
                    selll = true;
                }
            }

            if (selll)
            {
                return(BadRequest("Not a valid Book id"));
            }
            else
            {
                using (var ctx = new BooksEntities())
                {
                    var bookrequest = ctx.Requests
                                      .Where(s => s.Book_Id == id)
                                      .FirstOrDefault();
                    if (bookrequest != null)
                    {
                        ctx.Entry(bookrequest).State = System.Data.Entity.EntityState.Deleted;
                        ctx.SaveChanges();
                    }
                    var bookapproved = ctx.Seller_Approved_book
                                       .Where(s => s.Book_Id == id)
                                       .FirstOrDefault();
                    if (bookapproved != null)
                    {
                        ctx.Entry(bookapproved).State = System.Data.Entity.EntityState.Deleted;
                        ctx.SaveChanges();
                    }

                    var imglist = (from i in db.Images
                                   where i.Book_Id == id
                                   select i.Id).ToList();

                    foreach (var item in imglist)
                    {
                        var img = db.Images.Where(e => e.Id == item).First();
                        if (img != null)
                        {
                            db.Images.Remove(img);
                            db.SaveChanges();
                        }
                    }
                    var book = ctx.Books
                               .Where(s => s.Id == id)
                               .FirstOrDefault();

                    ctx.Entry(book).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }
            }

            return(Ok());
        }
コード例 #13
0
 public void UpdateReview(Review review)
 {
     context.Entry(review).State = EntityState.Modified;
 }