public ActionResult Edit(Models.LoaiSP editType) { if (Session["accname"] == null) { Session["accname"] = null; return(RedirectToAction("Login", "Account")); } else { ViewBag.cateListEdit = new SelectList(dbType.DanhMucs, "MaDanhMuc", "TenDanhMuc"); try { if (ModelState.IsValid) { //dbType.Entry(editType).State = System.Data.Entity.EntityState.Modified; //dbType.SaveChanges(); aDB.SuaLoaiSP(editType); 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.LoaiSP createType) { if (Session["accname"] == null) { Session["accname"] = null; return(RedirectToAction("Login", "Account")); } else { ViewBag.cateListCreate = new SelectList(dbType.DanhMucs, "MaDanhMuc", "TenDanhMuc"); try { if (ModelState.IsValid) { //dbType.ProductTypes.Add(createType); //dbType.SaveChanges(); aDB.ThemLoaiSP(createType); 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()); } }