public ActionResult Create(Books books, HttpPostedFileBase image) { var categoryAccess = new CategoriesAccess(); ViewBag.CategoryId = new SelectList(categoryAccess.ReadCategories().Where(x => x.Id != 1), "Id", "Name"); if (ModelState.IsValid) { if (image != null && image.ContentLength > 0) { // Lưu hình vào thư mục var filename = Server.MapPath("~/UploadFiles/" + Path.GetFileName(image.FileName)); image.SaveAs(filename); books.Image = Path.GetFileName(image.FileName); } var sess = (UserLogin)Session[CommonConstant.USER_SESSION]; books.CreatedBy = sess.Username; books.CreatedDate = DateTime.Now; books.ModifiedBy = sess.Username; books.ModifiedDate = DateTime.Now; long id = access.CreateBook(books); if (id > 0) { return(RedirectToAction("Index", "Book")); } else if (id == 0) { ModelState.AddModelError("", "Sách đã tồn tại"); } else { ModelState.AddModelError("", "Thêm sách thất bại"); } } return(View("Create")); }
public ActionResult Create() { var categoryAccess = new CategoriesAccess(); ViewBag.CategoryId = new SelectList(categoryAccess.ReadCategories().Where(x => x.Id != 1), "Id", "Name"); return(View()); }
public ActionResult Update(int id) { var categoryAccess = new CategoriesAccess(); ViewBag.BookId = new SelectList(categoryAccess.ReadCategories().Where(x => x.Id != 1), "Id", "Name", id); var book = access.GetBookById(id); return(View(book)); }
public PartialViewResult BookCategory() { var model = new CategoriesAccess().ReadCategories().Where(x => x.Id != 1); return(PartialView(model)); }