BookMgnt.Controllers.BookController.Create C# (CSharp) Method

Create() private method

private Create ( Book book, System.Web.HttpPostedFileBase imagePath ) : System.Web.Mvc.ActionResult
book BookMgnt.Models.Book
imagePath System.Web.HttpPostedFileBase
return System.Web.Mvc.ActionResult
        public ActionResult Create(Book book, HttpPostedFileBase imagePath)
        {
            if (ModelState.IsValid)
            {
                if(imagePath != null && imagePath.ContentLength > 0)
                {
                    string pic = System.IO.Path.GetFileName(imagePath.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/Content/imageBook"), pic);
                    if (System.IO.File.Exists(path))
                    {
                        int count = 2;
                        while (System.IO.File.Exists(path))
                        {
                            pic = count.ToString() + pic;
                            path = System.IO.Path.Combine(Server.MapPath("~/Content/imageBook"), pic);
                        }
                    }
                    imagePath.SaveAs(path);
                    book.imagePath = pic;
                }
                db.Books.Add(book);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.CategoriesID = new SelectList(db.Categories, "ID", "Name");
            return View(book);
        }

Same methods

BookController::Create ( ) : System.Web.Mvc.ActionResult