Пример #1
0
        public ActionResult InsertBook(BookManagement.Models.Books.AddBookView book, HttpPostedFileBase upload_File)
        {
            BookDAO _bookDAO = new BookDAO();

            if (ModelState.IsValid)
            {
                if (_bookDAO.CheckBook(book.Name, book.PublisherID, book.PublishedDate) == true)
                {
                    ModelState.AddModelError("", "This book is already exsisted!");
                    SetViewBag();
                    return(View("InsertBook"));
                }
                if ((upload_File.ContentLength < 0) || (upload_File == null))
                {
                    SetMessage("ERROR", "Book is not added!");
                    SetViewBag();
                    return(View("InsertBook"));
                }
                string relativePath = "~/Content/Img/Books/" + Path.GetFileName(upload_File.FileName);
                string physicalPath = Server.MapPath(relativePath);
                upload_File.SaveAs(physicalPath);
                if (_bookDAO.InsertBook(book, upload_File.FileName) == false)
                {
                    SetMessage("ERROR", "Book is not added!");
                    SetViewBag();
                    return(View("InsertBook"));
                }
                SetMessage("SUCCESS", "Book is added");
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "");
            }
            SetViewBag();
            SetMessage("ERROR", "Book is not added!");
            return(View("InsertBook", book));
        }