Пример #1
0
        public async Task <bool> SaveBookDetail(BookModel singleBookModel)
        {
            bool isSuccess = false;

            using (var context = new BookManagementContext())
            {
                var book = new Book()
                {
                    Isbn            = singleBookModel.Isbn,
                    BookId          = singleBookModel.BookId,
                    BookName        = singleBookModel.BookName,
                    BookDescription = singleBookModel.BookName,
                    BookCategoryId  = singleBookModel.BookCategoryId,
                    Price           = singleBookModel.Price,
                    AuthorId        = singleBookModel.AuthorId,
                    PulisherId      = singleBookModel.PulisherId,
                    Quantity        = singleBookModel.Quantity
                };

                context.Book.Add(book);
                context.SaveChanges();
                isSuccess = true;
            }

            return(isSuccess);
        }
Пример #2
0
        public async Task <bool> DeleteBookDetail(int id)
        {
            bool isSuccess = false;

            using (var context = new BookManagementContext())
            {
                var book = context.Book.FirstOrDefault(b => b.BookId == id);

                context.Book.Remove(book);
                context.SaveChanges();
                isSuccess = true;
            }

            return(isSuccess);
        }
Пример #3
0
        public async Task <bool> UpdateBookDetail(int id, BookModel singleBookModel)
        {
            bool isSuccess = false;

            using (var context = new BookManagementContext())
            {
                var book = context.Book.FirstOrDefault(b => b.BookId == id);

                book.Isbn            = singleBookModel.Isbn;
                book.BookId          = singleBookModel.BookId;
                book.BookName        = singleBookModel.BookName;
                book.BookDescription = singleBookModel.BookDescription;
                book.BookCategoryId  = singleBookModel.BookCategoryId;
                book.Price           = singleBookModel.Price;
                book.AuthorId        = singleBookModel.AuthorId;
                book.PulisherId      = singleBookModel.PulisherId;
                book.Quantity        = singleBookModel.Quantity;

                context.SaveChanges();
                isSuccess = true;
            }

            return(isSuccess);
        }
Пример #4
0
 /// <summary>
 /// Save change Database
 /// </summary>
 /// <returns>number rows change</returns>
 public int Save()
 {
     return(context.SaveChanges());
 }