Ejemplo n.º 1
0
 public bool InsertBook(BookManagement.Models.Books.AddBookView book, string img_name)
 {
     //DateTime publishedDate = DateTime.ParseExact(book.PublishedDate.ToString(), "YYYY-MM-DD", CultureInfo.InvariantCulture);
     //DateTime addedDate = DateTime.ParseExact(System.DateTime.Now.ToString(), "YYYY-MM-DD HH:MI:SS", CultureInfo.InvariantCulture);
     //DateTime modDate = DateTime.ParseExact(System.DateTime.Now.ToString(), "YYYY-MM-DD HH:MI:SS", CultureInfo.InvariantCulture);
     try
     {
         _db.Books.Add(new Book
         {
             Name          = book.Name,
             Description   = book.Description,
             StatusID      = book.StatusID,
             Price         = book.Price,
             PublisherID   = book.PublisherID,
             PublishedDate = book.PublishedDate,
             GenreID       = book.GenreID,
             AddedDate     = System.DateTime.Now,
             ModifiedDate  = System.DateTime.Now,
             Img_Link      = img_name,
             AuthorID      = book.AuthorID
         });
         _db.SaveChanges();
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
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));
        }