Exemple #1
0
        public ActionResult AddBook(BOOK book, List <int> Authors, List <int> Categories,
                                    List <HttpPostedFileBase> bookImages, List <HttpPostedFileBase> bookSoftCopy)
        {
            try
            {
                book.CREATED_DATE = DateTime.Now;
                book = BookModel.AddBook(book);

                foreach (int aID in Authors)
                {
                    BOOK_AUTHOR bookAuthor = new BOOK_AUTHOR();
                    bookAuthor.BOOKID   = book.BOOKID;
                    bookAuthor.AUTHORID = aID;
                    AuthorModel.AddBookAuthor(bookAuthor);
                }

                foreach (int bCID in Categories)
                {
                    BOOK_CATEGORY bookCat = new BOOK_CATEGORY();
                    bookCat.BOOKID     = book.BOOKID;
                    bookCat.CATEGORYID = bCID;
                    CategoryModel.AddBookCategory(bookCat);
                }

                foreach (HttpPostedFileBase image in bookImages)
                {
                    String     fname     = Generator.RandomString(10) + "." + image.FileName.Split('.')[image.FileName.Split('.').Length - 1];
                    string     path      = Server.MapPath("~/UserImages/") + fname;
                    BOOK_IMAGE bookImage = new BOOK_IMAGE();
                    bookImage.BOOKID    = book.BOOKID;
                    bookImage.IMAGEPATH = "/UserImages/" + fname;
                    image.SaveAs(path);
                    BookModel.AddBookImage(bookImage);
                }
                if (bookSoftCopy != null)
                {
                    foreach (HttpPostedFileBase bookSC in bookSoftCopy)
                    {
                        String        fname = Generator.RandomString(10) + "." + bookSC.FileName.Split('.')[bookSC.FileName.Split('.').Length - 1];
                        string        path  = Server.MapPath("~/UserImages/") + fname;
                        BOOK_SOFTCOPY bSC   = new BOOK_SOFTCOPY();
                        bSC.BOOKID   = book.BOOKID;
                        bSC.FILEPATH = "/UserImages/" + fname;
                        bSC.FILESIZE = bookSC.ContentLength;
                        bookSC.SaveAs(path);
                        BookModel.AddBookSoftCopy(bSC);
                    }
                }
                ViewBag.Message = SuccessMessage.BOOK_ADDED;
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;
            }

            initialiseViewBag();
            return(View(book));
        }
        public void AddBook()
        {
            string author         = _viewAddBook.Author;
            string name           = _viewAddBook.Name;
            string publisher      = _viewAddBook.Publisher;
            int    datepublishing = _viewAddBook.DatePublishing;
            var    book           = new Book(author, name, publisher, datepublishing);

            _bookModel.AddBook(book);
        }
        public ActionResult AddBook(BookModel model)
        {
            // Redirect is the user isn't an admin
            if (!IdentityModel.CurrentUserAdmin)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.Error = String.Empty;
            model         = BindModel(model);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.AddBook())
            {
                ViewBag.Error = "Het boek is toegevoegd!";
                return(View(model));
            }
            ViewBag.Error = "Het boek is niet toegevoegd, probeer het later nog eens!";
            return(View(model));
        }