public ActionResult AddBook(Book model) { ViewData["CategoryID"] = new SelectList( //db.Categories.ToList() categoryConcrete.GetCategoryList() .Select(x => new { x.CategoryID, x.CategoryName }), "CategoryID", "CategoryName"); ViewData["AuthorID"] = new SelectList( //db.Authors.ToList() authorConcrete.GetAuthorList() .Select(x => new { x.AuthorID, AuthorName = x.FirstName + " " + x.LastName }) , "AuthorID", "AuthorName"); ViewData["StatusID"] = new SelectList( //db.Statuses.ToList() statusConcrete.GetStatusList() .Select(x => new { x.StatusID, x.StatusName }), "StatusID", "StatusName"); model.UserID = User.Identity.GetUserId(); model.IsDelete = false; model.IsActive = true; if (Request.Files.Count > 0) { try { var file = Request.Files[0]; string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/img/Books"), pic); // file is uploaded file.SaveAs(path); model.ImageUrl = "~/img/Books/" + pic; } catch (Exception ex) { ModelState.AddModelError("Error", "Resim yüklenemiyor!" + ex.Message); return(View(model)); } } if (false && !ModelState.IsValid) { ModelState.AddModelError("Error", "Bir hata oluştu!"); return(View(model)); } else { try { //repBook.Add(model); //uow.SaveChanges(); bookConcrete.AddBook(model); return(RedirectToAction("MyBooks", "Book")); } catch (Exception ex) { ModelState.AddModelError("Error", ex); return(View(model)); } } }