public ActionResult Create(tblCriteria tblcriteria, FormCollection collection, int[] MutilMenu) { db.tblCriterias.Add(tblcriteria); db.SaveChanges(); var listcri = db.tblCriterias.OrderByDescending(p => p.id).Take(1).ToList(); int idCri = int.Parse(listcri[0].id.ToString()); if (MutilMenu != null) { foreach (var idCate in MutilMenu) { tblGroupCriteria tblgroupcrieria = new tblGroupCriteria(); tblgroupcrieria.idCate = idCate; tblgroupcrieria.idCri = idCri; db.tblGroupCriterias.Add(tblgroupcrieria); db.SaveChanges(); } } Updatehistoty.UpdateHistory("Add tblcriteria", Request.Cookies["Username"].Values["FullName"].ToString(), Request.Cookies["Username"].Values["UserID"].ToString()); if (collection["btnSave"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info alert1\">Bạn đã thêm thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Criteria/Index")); } if (collection["btnSaveCreate"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info\">Bạn đã thêm thành công, mời bạn thêm tiêu trí mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Criteria/Create")); } return(Redirect("Index")); }
public ActionResult Edit(tblCriteria tblcriteria, int id, FormCollection collection, int[] MutilMenu) { if (ModelState.IsValid) { db.Entry(tblcriteria).State = EntityState.Modified; db.SaveChanges(); var listcri = db.tblGroupCriterias.Where(p => p.idCri == id).ToList(); for (int i = 0; i < listcri.Count; i++) { db.tblGroupCriterias.Remove(listcri[i]); db.SaveChanges(); } if (MutilMenu != null) { foreach (var idCates in MutilMenu) { tblGroupCriteria tblgroupcrieria = new tblGroupCriteria(); tblgroupcrieria.idCate = idCates; tblgroupcrieria.idCri = id; db.tblGroupCriterias.Add(tblgroupcrieria); db.SaveChanges(); } } #region [Updatehistory] Updatehistoty.UpdateHistory("Edit tblcriteria", Request.Cookies["Username"].Values["FullName"].ToString(), Request.Cookies["Username"].Values["UserID"].ToString()); #endregion if (collection["btnSave"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info alert1\">Bạn đã sửa thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Criteria/Index")); } if (collection["btnSaveCreate"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info\">Bạn đã thêm thành công, mời bạn thêm mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Criteria/Create")); } } return(View(tblcriteria)); }