public ActionResult Create(Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoriesId = new SelectList(db.Categories, "CategoriesId", "CategoriesName", book.CategoriesId);
            return View(book);
        }
Beispiel #2
0
 public void AddBook()
 {
     List<Book> list = new List<Book>();
     var book1 = new Book()
     {
         BookName = "The Gruffalo in Scots",
         Price = "50",
         CategoriesId = 2,
         Decription = @"We don't think there's anyone, anywhere in the book-loving world who hasn't heard of the Gruffalo.
         Julia Donaldson's lovable and unforgettable creation has enchanted little ones for over a decade and now young Scottish
         readers can enjoy this very special edition of Julia's tale starring the much-adored Gruffalo, now told in flowing Scots!
         The original story's illustrations by Axel Scheffler help make this the perfect keepsake for any proud Scot!",
         DateUpdate = new DateTime(2014, 3, 26),
         PageNumber = "60",
         PictureName = "GRUS_childrenBook.jpg",
         NumberOfViews = 0,
         IsDelete = false
     };
     var book2 = new Book()
     {
         BookName = "Old Macdonald Had a Zoo",
         Price = "10",
         CategoriesId = 2,
         Decription = @"After winning the lottery, Old MacDonald decides to sell up his farm
         and buy a zoo with his winnings - but what will the old farm animals make of this?
         With liftable flaps adding extra interaction to this brilliant twist on a well-known tale,
         the book hilariously reveals how the zoo animals picked off the farm animals one by one.
         From the talented mind of Curtis Jobling and the amazing illustrator Tom McLaughlin,
         this is a laugh-out-loud book for child and parent.",
         DateUpdate = new DateTime(2014, 3, 26),
         PageNumber = "20",
         PictureName = "OLM2.jpg",
         NumberOfViews = 1,
         IsDelete = false
     };
     var book3 = new Book()
     {
         BookName = "Books Signed by Musicians",
         Price = "120",
         CategoriesId = 5,
         Decription = @"Music is the soundtrack to our memories and one of life’s
         great pleasures. And the people who write, sing and play live a rollercoaster existence in the glare of the public eye.
         These stars suffer heartbreak and heartache, personal tragedies,
         drug and alcohol addiction, in-fighting and real fighting,
         financial woes despite earning a fortune, and the odd loneliness of life on the road.
         These books are fascinating reads and signed too.",
         DateUpdate = new DateTime(2010, 3, 26),
         PageNumber = "256",
         PictureName = "greendale-neil-young.jpg",
         NumberOfViews = 1,
         IsDelete = false
     };
     var book4 = new Book()
     {
         BookName = "Pro Asynchronous Programming with .NET",
         Price = "352",
         CategoriesId = 6,
         Decription = @"Pro Asynchronous Programming with .NET teaches the essential
                     skill of asynchronous programming in .NET. It answers critical questions
                     in .NET application development, such as: how do I keep my program responding at all times to
                     keep my users happy? how do I make the most of the available hardware? how can I improve performance?
                     <br/>
                     In the modern world, users expect more and more from their applications and devices,
                     and multi-core hardware has the potential to provide it.
                     But it takes carefully crafted code to turn that potential into responsive,
                     scalable applications.",
         DateUpdate = new DateTime(2010, 6, 12),
         PageNumber = "352",
         PictureName = "pro_asynchronous_programming_with_.net.jpg",
         NumberOfViews = 3,
         IsDelete = false
     };
     var book5 = new Book()
     {
         BookName = "Oracle PL/SQL Programming, 6th Edition",
         Price = "500",
         CategoriesId = 6,
         Decription = @"Considered the best Oracle PL/SQL programming guide by the Oracle
                     community, this definitive guide is precisely what you need
                     to make the most of Oracle's powerful procedural language.
                     The sixth edition describes the features and capabilities of
                     PL/SQL up through Oracle Database 12c Release 1.
                     <br/>
                     Hundreds of thousands of PL/SQL developers have benefited
                     from this book over the last twenty years;
                     this edition continues that tradition.
                     With extensive code examples and a lively sense of humor,
                     this book explains language fundamentals,
                     explores advanced coding techniques,
                     and offers best practices to help you solve real-world problems.",
         DateUpdate = new DateTime(2012, 12, 21),
         PageNumber = "1392",
         PictureName = "oracle_plsql_programming_6th_edition.jpg",
         NumberOfViews = 3,
         IsDelete = false
     };
     var book6 = new Book()
     {
         BookId=6,
         BookName = "Java Quick Syntax Reference",
         Price = "120",
         CategoriesId = 6,
         Decription = @"The Java Quick Syntax Reference is a condensed code and syntax
                     reference to the Java programming language.
                     It presents the essential Java syntax in a well-organized
                     format that can be used as a handy reference.
     `                       <br/>
                     You won't find any technical jargon, bloated samples,
                     drawn out history lessons or witty stories in this book.
                     What you will find is a language reference that is concise,
                     to the point and highly accessible. The book is packed with
                     useful information and is a must-have for any Java programmer.",
         DateUpdate = new DateTime(2013, 1, 12),
         PageNumber = "302",
         PictureName = "java_quick_syntax_reference.jpg",
         NumberOfViews = 3,
         IsDelete = false
     };
     var book7 =new Book()
     {
         BookId = 7,
         BookName = "Java Network Programming, 4th Edition",
         Price = "120",
         CategoriesId = 6,
         Decription = @"The Java Quick Syntax Reference is a condensed code and syntax
                     reference to the Java programming language.
                     It presents the essential Java syntax in a well-organized
                     format that can be used as a handy reference.
     `                       <br/>
                     You won't find any technical jargon, bloated samples,
                     drawn out history lessons or witty stories in this book.
                     What you will find is a language reference that is concise,
                     to the point and highly accessible. The book is packed with
                     useful information and is a must-have for any Java programmer.",
         DateUpdate = new DateTime(2013, 1, 12),
         PageNumber = "502",
         PictureName = "java_network_programming_4th_edition.jpg",
         NumberOfViews = 1,
         IsDelete = false
     };
        var book8 =new Book()
     {
         BookId = 8,
         BookName = "LINQ to Objects Using C# 4.0",
         Price = "222",
         CategoriesId = 6,
         Decription = @"Using LINQ to Objects, .NET developers can write queries over
                     object collections with the same deep functionality that was once available
                     only with SQL and relational databases. Now, for the first time,
                     developers have a comprehensive and authoritative guide to applying LINQ
                     to Objects in real-world software. Microsoft MVP Troy Magennis
                     introduces state-of-the-art techniques for working with in-memory
                     collections more elegantly and efficiently - and writing code
                     that is exceptionally powerful, robust, and flexible.",
         DateUpdate = new DateTime(2010, 9, 30),
         PageNumber = "336",
         PictureName = "linq_to_objects_using_c_4.0.jpg",
         NumberOfViews = 1,
         IsDelete = false
     };
     var book9= new Book()
     {
         BookId = 9,
         BookName = "Learning MySQL",
         Price = "100",
         CategoriesId = 6,
         Decription = @"Whether you're running a business, keeping track of members andmeetings
                     for a club, or just trying to organize a large and diversecollection of information,
                     you'll find the MySQL database engineuseful for answering questions such as:
                     Which are my top ten fastest-selling products? How frequently does this person
                     come to our facility? What was the highest, lowest,
                     and average score of the team last season?",
         DateUpdate = new DateTime(2006, 3, 10),
         PageNumber = "622",
         PictureName = "learning_mysql.jpg",
         NumberOfViews = 12,
         IsDelete = false
     };
        var book10=new Book()
     {
         BookId = 10,
         BookName = "50 Tips and Tricks for MongoDB Developers",
         Price = "10",
         CategoriesId = 6,
         Decription = @"Getting started with MongoDB is easy,
                     but once you begin building applications with it, you'll face some complex issues.
                     What are the tradeoffs between normalized and denormalized data?
                     How do you handle replica set failure and failover?
                     This collection of MongoDB tips, tricks, and hacks helps you
                     resolve issues with everything from application design and implementation
                     to data safety and monitoring.",
         DateUpdate = new DateTime(2011, 4, 17),
         PageNumber = "66",
         PictureName = "50_tips_and_tricks_for_mongodb_developers.jpg",
         NumberOfViews = 12,
         IsDelete = false
     };
     db.Books.Add(book1);
     db.Books.Add(book2);
     db.Books.Add(book3);
     db.Books.Add(book4);
     db.Books.Add(book5);
     db.Books.Add(book6);
     db.Books.Add(book7);
     db.Books.Add(book8);
     db.Books.Add(book9);
     db.Books.Add(book10);
     db.SaveChanges();
 }
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CategoriesId = new SelectList(db.Categories, "CategoriesId", "CategoriesName", book.CategoriesId);
     return View(book);
 }