Beispiel #1
0
        public ActionResult Create(Book book, HttpPostedFileBase uploadimage)
        {
            string filePath = "";

            if (uploadimage.ContentLength > 0)
            {
                string fileName = Guid.NewGuid().ToString() + " " + uploadimage.FileName;
                filePath = Path.Combine(HttpContext.Server.MapPath("~/Content/Image"), fileName);
                uploadimage.SaveAs(filePath);
                book.CoverImage = fileName;
            }
            using (BooksDAL svBooks = new BooksDAL())
            {
                try
                {
                    svBooks.Add(book);
                    TempData["Pesan"] = Helper.KotakPesan.GetPesan("success",
                                                                   "Sukses ", "Data berhasil ditambahkan");
                }
                catch (Exception ex)
                {
                    TempData["Pesan"] = Helper.KotakPesan.GetPesan("danger",
                                                                   "Error! ", ex.Message);
                }
            }
            return(RedirectToAction("Index"));
        }