Пример #1
0
        public bool Delete(int id)
        {
            var item = dbContext.Books.Include(b => b.Id == id);

            dbContext.Entry(item).State = EntityState.Deleted;
            try
            {
                dbContext.SaveChanges();
                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }
        }
 public bool Add(BorrowBook borrowBook)
 {
     try
     {
         dbContext.BorrowBooks.Add(borrowBook);
         var book = dbContext.Books.SingleOrDefault(b => b.Id == borrowBook.BookId);
         if (book != null)
         {
             if (book.AvailableNumber > 0)
             {
                 book.AvailableNumber--;
             }
             else
             {
                 return(false);
             }
         }
         dbContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Пример #3
0
 public bool Add(Borrower borrower)
 {
     try
     {
         dbContext.Borrowers.Add(borrower);
         dbContext.SaveChanges();
         return(true);
     }
     catch (DbUpdateConcurrencyException)
     {
         return(false);
     }
 }