public ActionResult EditProduct(int?productId, bool success = false) { if (!User.IsInRole("Admin")) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 403." , errorDetail = "Bạn không có quyền truy cập" })); } ViewBag.IsAdmin = true; if (productId == null) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 404." , errorDetail = "Không xác định sản phẩm" })); } ViewBag.User = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); return(View(ProductVM.GenerateProductVM(db, productId, success))); }
public ActionResult AddProduct(bool success = false) { if (!User.IsInRole("Admin")) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 403." , errorDetail = "Bạn không có quyền truy cập" })); } ViewBag.IsAdmin = true; ViewBag.User = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); return(View(ProductVM.GenerateProductVM(db, success))); }
public ActionResult AddProduct(ProductVM myModel, FormCollection collection) { if (!User.IsInRole("Admin")) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 403." , errorDetail = "Bạn không có quyền truy cập" })); } ViewBag.IsAdmin = true; if (ModelState.IsValid) { myModel.Product.ProductDetails = myModel.Details; db.Products.Add(myModel.Product); db.SaveChanges(); if (myModel.Details != null) { foreach (ProductDetail detail in myModel.Details) { UpdateCountAuthor(detail.AuthorId); } } UpdateCountCategory(myModel.Product.CategoryId); return(RedirectToAction("AddProduct", "Staff", new { success = true })); } else { ViewBag.User = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); return(View(ProductVM.GenerateProductVM(db, false))); } }