コード例 #1
0
        public bool UpdateBook(int bookId, Book book)
        {
            try
            {
                using (var jenkinsContext = new JenkinsCrudContext())
                {
                    var currentBook = jenkinsContext.Books.FirstOrDefault(x => !x.IsDeleted && x.Id == bookId);

                    if (currentBook == null)
                    {
                        return(false);
                    }

                    currentBook.Isbn             = book.Isbn;
                    currentBook.PublicationDate  = book.PublicationDate;
                    currentBook.PublicationPlace = book.PublicationPlace;
                    currentBook.Title            = book.Title;
                    currentBook.AuthorFirstName  = book.AuthorFirstName;
                    currentBook.AuthorLastName   = book.AuthorLastName;

                    jenkinsContext.Entry(currentBook).State = EntityState.Modified;

                    return(jenkinsContext.SaveChanges() > 0);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #2
0
        public bool DeleteBook(int bookId)
        {
            try
            {
                using (var jenkinsContext = new JenkinsCrudContext())
                {
                    var currentBook = jenkinsContext.Books.FirstOrDefault(x => x.Id == bookId);

                    if (currentBook == null)
                    {
                        return(false);
                    }

                    currentBook.IsDeleted = true;

                    jenkinsContext.Entry(currentBook).State = EntityState.Modified;

                    return(jenkinsContext.SaveChanges() > 0);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #3
0
        public bool AddBook(Book book)
        {
            try
            {
                using (var jenkinsContext = new JenkinsCrudContext())
                {
                    jenkinsContext.Books.Add(book);

                    return(jenkinsContext.SaveChanges() > 0);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }