public ActionResult Create()
        {
            prepare();

            Book book = new Book { Id = 0, CoverId = 1, GenreId = 1, Year = 2000 };
            return PartialView("ModalView", book);
        }
        public ActionResult GetBooks(Book book)
        {
            prepare();
            book.Cover = context.Covers.Find(book.CoverId);
            book.Genre = context.Genres.Find(book.GenreId);

            if(book.Id != 0)
            {
                Book edited = context.Books.Find(book.Id);
                edited.Title = book.Title;
                edited.Description = book.Description;
                edited.Author = book.Author;
                edited.Year = book.Year;
                edited.Cover = book.Cover;
                edited.Genre = book.Genre;
            }
            else
                context.Books.Add(book);

            context.SaveChanges();

            List<Book> books = context.Books.ToList();
            return PartialView("ListView", books);
        }
        public ActionResult Update()
        {
            prepare();

            int id = Int32.Parse(Request.Form["id"]);
            Book book = new Book { Id = 0 };

            if (id != 0)
                book = context.Books.Find(id);

            return PartialView("ModalView", book);
        }
        //funkcja inicjalizuje bazę przy pierwszym uruchomieniu
        void initialize()
        {
            if (context.Covers.Count() == 0)
            {
                context.Covers.Add(new Cover { Data = "twarda" });
                context.Covers.Add(new Cover { Data = "miękka" });
            }

            context.SaveChanges();

            if (context.Genres.Count() == 0)
            {
                context.Genres.Add(new Genre { Data = "sf" });
                context.Genres.Add(new Genre { Data = "sensacja" });
                context.Genres.Add(new Genre { Data = "kryminał" });
            }

            context.SaveChanges();

            if (context.Books.Count() == 0)
            {
                Book book = new Book { Id = 0, Author = "Grzegorz XV", CoverId = 1, GenreId = 1, Description = "", Title = "Nie ma nas", Year = 1901 };
                book.Cover = context.Covers.Find(1);
                book.Genre = context.Genres.Find(1);
                context.Books.Add(book);

                book = new Book { Id = 0, Author = "Miodek", CoverId = 1, GenreId = 1, Description = "ąćęłńóśźż", Title = "Polskie znaki", Year = 1999 };
                book.Cover = context.Covers.Find(2);
                book.Genre = context.Genres.Find(2);
                context.Books.Add(book);
            }

            context.SaveChanges();
        }
 public ActionResult ShowBook(Book book)
 {
     return PartialView("BookView", book);
 }