예제 #1
0
 public bool AddBook(BookModel newBook)
 {
     try
     {
         using (BooksDBEntities db = new BooksDBEntities())
         {
             db.Books.Add(
                 new Book()
             {
                 Price      = newBook.Price,
                 NumOfPages = newBook.NumOfPages,
                 BookName   = newBook.BookName,
                 Author     = new Author
                 {
                     Age   = newBook.Author.Age,
                     Image = newBook.Author.Image,
                     Name  = newBook.Author.Name
                 }
             }
                 );
             db.SaveChanges();
             return(true);
         };
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public ActionResult Index()
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         List <Book> list = db.uspGetBooks().ToList();
         return(View(list));
     }
 }
 // GET: Books/Details/5
 public ActionResult Details(int id)
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         Book book = db.uspGetBooksById(id).FirstOrDefault();
         return(View(book));
     }
 }
예제 #4
0
 public List <AuthorModel> GetAllAuthors()
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         return(db.Authors.Select(a =>
                                  new AuthorModel()
         {
             Age = a.Age,
             Image = a.Image,
             Name = a.Name
         }).ToList());
     }
 }
예제 #5
0
 public AuthorModel GetAuthor(string name)
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         return(db.Authors
                .Where(a => a.Name == name)
                .Select(a =>
                        new AuthorModel()
         {
             Age = a.Age,
             Image = a.Image,
             Name = a.Name
         }).FirstOrDefault());
     };
 }
예제 #6
0
 public bool RemoveBook(string name)
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         var BookToRemove = db.Books
                            .Where(b => b.BookName == name).FirstOrDefault();
         if (BookToRemove != null)
         {
             db.Books.Remove(BookToRemove);
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     };
 }
예제 #7
0
 public bool RemoveAuthor(string name)
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         var AuthorToRemove = db.Authors
                              .Where(a => a.Name == name).FirstOrDefault();
         if (AuthorToRemove != null)
         {
             db.Authors.Remove(AuthorToRemove);
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     };
 }
예제 #8
0
        public bool EditAuthor(string name, AuthorModel newAuthor)
        {
            try {
                using (BooksDBEntities db = new BooksDBEntities())
                {
                    var toEdit = db.Authors
                                 .Where(a => a.Name == name).FirstOrDefault();

                    toEdit.Age   = newAuthor.Age;
                    toEdit.Image = newAuthor.Image;
                    db.SaveChanges();
                    return(true);
                };
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #9
0
        public bool EditBook(string name, BookModel newBook)
        {
            try
            {
                using (BooksDBEntities db = new BooksDBEntities())
                {
                    var toEdit = db.Books
                                 .Where(b => b.BookName == name).FirstOrDefault();

                    toEdit.NumOfPages = newBook.NumOfPages;
                    toEdit.Price      = newBook.Price;
                    db.SaveChanges();
                    return(true);
                };
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #10
0
        public List <BookModel> GettAllBooks()
        {
            using (BooksDBEntities db = new BooksDBEntities())
            {
                return(db.Books.Select(b =>
                                       new BookModel()
                {
                    BookName = b.BookName,
                    NumOfPages = b.NumOfPages,
                    Price = b.Price,
                    Author = new AuthorModel()
                    {
                        Age = b.Author.Age,
                        Image = b.Author.Image,
                        Name = b.Author.Name
                    }
                }

                                       ).ToList());
            }
        }
예제 #11
0
 public BookModel GetBook(string name)
 {
     using (BooksDBEntities db = new BooksDBEntities())
     {
         return(db.Books
                .Where(b => b.BookName == name)
                .Select(b =>
                        new BookModel()
         {
             BookName = b.BookName,
             NumOfPages = b.NumOfPages,
             Price = b.Price,
             Author = new AuthorModel()
             {
                 Age = b.Author.Age,
                 Image = b.Author.Image,
                 Name = b.Author.Name
             }
         }).FirstOrDefault());
     };
 }
예제 #12
0
 public bool AddAuthor(AuthorModel newAuthor)
 {
     try
     {
         using (BooksDBEntities db = new BooksDBEntities())
         {
             db.Authors.Add(
                 new Author()
             {
                 Age   = newAuthor.Age,
                 Image = newAuthor.Image,
                 Name  = newAuthor.Name
             }
                 );
             db.SaveChanges();
             return(true);
         };
     }
     catch (Exception)
     {
         return(false);
     }
 }