public ActionResult RoleSave(B_ROLE entity) { BLL.Organize.Role role = new BLL.Organize.Role(); string action = Request.Form["action"]; string range = Request.Form["range"]; if (ModelState.IsValid) { bool save; try { save = role.Save(entity); List <int> listActionId = new List <int>(); if (!string.IsNullOrEmpty(action)) { foreach (string a in action.Split(',').ToList()) { listActionId.Add(int.Parse(a)); } } List <string> listRangeId = new List <string>(); if (!string.IsNullOrEmpty(range)) { foreach (string a in range.Split(',').ToList()) { listRangeId.Add(a); } } //role.SaveRoleAction(entity.ID, listActionId); Anchor.FA.BLL.Organize.Role.SaveRoleAction(entity.ID, listActionId, listRangeId); } catch (Exception ex) { Log4Net.LogError("RoleSave", ex.ToString()); 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 static bool Save(B_ROLE entity) { using (MainDataContext dbContext = new MainDataContext()) { using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch)) { string sqlB; string sqlT; try { if (dbContext.B_ROLE.Count(t => t.ID == entity.ID) == 0) //添加 { //var list = from a in dbContext.B_ROLE select a.ID; //long total = list.LongCount(); //if (total == 0) //{ // entity.ID = 1; //} //else //{ // entity.ID = dbContext.B_ROLE.Max(a => a.ID) + 1; //} sqlB = string.Format(" INSERT INTO [B_ROLE]([ID],[Name],[Remark]) VALUES ({0},'{1}','{2}')", entity.ID, entity.Name, entity.Remark); sqlT = string.Format(" insert TRole ([编码],[名称],[顺序号],[是否有效])values ({0},'{1}',{2},{3})", entity.ID, entity.Name, 1, dbContext.TRole.Max(a => a.顺序号) + 1); } else //修改 { sqlB = string.Format(" update B_ROLE set name='{0}',remark='{1}' where id={2}", entity.Name, entity.Remark, entity.ID); sqlT = string.Format(" update TRole set 名称='{0}' where 编码={1}", entity.Name, entity.ID); } dbContext.ExecuteCommand(sqlB); dsContext.ExecuteCommand(sqlT); return(true); } catch (Exception ex) { Log4Net.LogError("Save Role", ex.Message); return(false); } } } }
public static object Edit(int?id) { using (MainDataContext dbContext = new MainDataContext()) { B_ROLE entity = null; if (id != null) { entity = dbContext.B_ROLE.FirstOrDefault(a => a.ID == id); } entity = entity ?? new B_ROLE { ID = -1, Name = string.Empty, Remark = string.Empty, }; return(entity); } }
public bool Save(B_ROLE entity) { return(DAL.Organize.Role.Save(entity)); }