public ActionResult Edit(Models.ProductTypes editType) { if (Session["accname"] == null) { Session["accname"] = null; return(RedirectToAction("Login", "Account")); } else { ViewBag.cateListEdit = new SelectList(dbType.Categories, "cateID", "cateName"); try { if (ModelState.IsValid) { dbType.Entry(editType).State = EntityState.Modified; dbType.SaveChanges(); ViewBag.EditTypeError = "Cập nhật loại sản phẩm thành công."; } } catch (Exception) { ViewBag.EditTypeError = "Không thể cập nhật loại sản phẩm."; } return(View()); } }
public ActionResult Create(Models.ProductTypes createType) { if (Session["accname"] == null) { Session["accname"] = null; return(RedirectToAction("Login", "Account")); } else { ViewBag.cateListCreate = new SelectList(dbType.Categories, "cateID", "cateName"); try { if (ModelState.IsValid) { dbType.ProductTypes.Add(createType); dbType.SaveChanges(); ViewBag.CreateTypeError = "Thêm loại sản phẩm thành công."; } } catch (Exception) { ViewBag.CreateTypeError = "Không thể thêm loại sản phẩm."; } return(View()); } }
public ActionResult Edit(Models.ProductTypes p) { if (ModelState.IsValid) { _c.TUpdate(p); return(RedirectToAction(actionName: nameof(Index))); } return(View(p.Id)); }
public ActionResult Create(Models.ProductTypes p) { if (ModelState.IsValid) { _c.TAdd(p); TempData["Save"] = "Product Type has been saved"; return(RedirectToAction(actionName: nameof(Index))); } return(View(p)); }
[ValidateAntiForgeryToken] // Security mechanism that .net implmented for us. Gets added to request and server checks if the request is not altered on the way public async Task <IActionResult> Create(Models.ProductTypes productTypes) { if (ModelState.IsValid) { _db.Add(productTypes); await _db.SaveChangesAsync(); //return RedirectToAction("Index"); //This can have typo return(RedirectToAction(nameof(Index))); } return(View(productTypes)); }
[ValidateAntiForgeryToken] // Security mechanism that .net implmented for us. Gets added to request and server checks if the request is not altered on the way public async Task <IActionResult> Edit(int id, Models.ProductTypes productTypes) { if (id != productTypes.Id) { return(NotFound()); } if (ModelState.IsValid) { _db.Update(productTypes); await _db.SaveChangesAsync(); //return RedirectToAction("Index"); //This can have typo return(RedirectToAction(nameof(Index))); } return(View(productTypes)); }
public ActionResult Details(Models.ProductTypes p) { return(RedirectToAction("Index")); }