Пример #1
0
 public ActionResult Create(Author newAuthor)
 {
     if (ModelState.IsValid)
     {
         bookRepository.Add(newAuthor);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Пример #2
0
        public ActionResult Create(BookAuthorViewModel newBookAuthor)
        {
            //Saving File Or Image
            string uploads  = Path.Combine(Hosting.WebRootPath, "Uploads");
            string FileName = newBookAuthor.File.FileName;
            string FullPath = Path.Combine(uploads, FileName);

            newBookAuthor.File.CopyTo(new FileStream(FullPath, FileMode.Create));

            var  author  = authorRepository.Find(newBookAuthor.Book.Author.ID);
            var  Book    = newBookAuthor.Book;
            Book newBook = new Book
            {
                ID          = Book.ID,
                Title       = Book.Title,
                Description = Book.Description,
                Author      = author,
                //Saving File Or Image
                ImageUrl = FileName
            };

            bookRepository.Add(newBook);
            return(RedirectToAction("Index"));
        }