public ActionResult ActionSave(B_ACTION entity) { BLL.Organize.Action Action = new BLL.Organize.Action(); if (ModelState.IsValid) { bool save; try { save = Action.Save(entity); } catch (Exception) { save = false; } if (save) { return(Json(new { IsSuccess = true, Message = "保存成功" }, "text/html", JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, Message = "保存失败" }, "text/html", JsonRequestBehavior.AllowGet)); } } return(View()); }
public ActionResult ActionEdit(int?id) { BLL.Organize.Action Action = new BLL.Organize.Action(); B_ACTION cot = Action.Edit(id) as B_ACTION; this.ViewData["entity"] = cot; ViewData["action"] = cot.ParentID == null ? 1000 : cot.ParentID; return(View()); }
public static object Edit(int?id) { using (MainDataContext dbContext = new MainDataContext()) { B_ACTION entity = null; if (id != null) { entity = dbContext.B_ACTION.FirstOrDefault(a => a.ID == id); } entity = entity ?? new B_ACTION { ID = 0, Url = string.Empty, Remark = string.Empty, ParentID = null, }; return(entity); } }
public static bool Save(B_ACTION entity) { using (MainDataContext dbContext = new MainDataContext()) { if (dbContext.B_ACTION.Count(a => a.ID == entity.ID) == 0) //添加 { //var list = from a in dbContext.B_ACTION select a.ID; //long total = list.LongCount(); //if (total == 0) //{ // entity.ID = 1; //} //else //{ // entity.ID = dbContext.B_ACTION.Max(a => a.ID) + 1; //} dbContext.B_ACTION.InsertOnSubmit(entity); dbContext.SubmitChanges(); return(true); } else //修改 { var model = dbContext.B_ACTION.FirstOrDefault(a => a.ID == entity.ID); model.Remark = entity.Remark; model.Url = entity.Url; model.Icon = entity.Icon; model.OrderID = entity.OrderID; model.ParentID = entity.ParentID; try { dbContext.SubmitChanges(); } catch (Exception e) { throw; } return(true); } } }
public bool Save(B_ACTION entity) { return(DAL.Organize.Action.Save(entity)); }