コード例 #1
0
        public ActionResult Create([Bind(Include = "BookId,Title,Description,Text,Visit,ImageName")] Book book
                                   , HttpPostedFileBase imageBook)
        {
            if (ModelState.IsValid)
            {
                if (imageBook != null && imageBook.IsImage())
                {
                    book.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageBook.FileName);
                    imageBook.SaveAs(Server.MapPath("/Content/Image/Book/" + book.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("/Content/Image/Book/" + book.ImageName),
                               Server.MapPath("/Content/Image/Book/Thumbnail/" + book.ImageName));

                    book.CreateDate = DateTime.Now;
                    _bookBusiness.Insert(book);
                    _bookBusiness.Save();
                    return(RedirectToAction("Index"));
                }

                return(View(book));
            }

            return(View(book));
        }
コード例 #2
0
 /// <summary>
 /// Inseri um livro chamando a camada de business
 /// </summary>
 /// <param name="book">Livro que será inserido</param>
 /// <returns>Livro inserido</returns>
 public BookModel Insert(BookModel book)
 {
     return(_bookBusiness.Insert(book));
 }
コード例 #3
0
 public void Insert([FromBody] Book value)
 {
     _bus.Insert(value);
 }