protected void add_ServerClick(object sender, EventArgs e) { var content = name.Text.Trim(); var value = CurrentNode; if (content.None()) { NotifyError(ap, "请输入要添加的角色名称"); return; } if (CurrentNode.HasValue) { var id = CurrentNode.Value; var role = DataContext.DepotRoleLoad(Depot.Id).Single(o => o.Id == id); role.Ordinal = ordinal.PeekValue(100); role.Name = content; if (role.State == State.启用) { role.Rights = "{0}{1}{2}".Formatted(r1.PeekValue(true).GetFirstChar(), r2.PeekValue(true).GetFirstChar(), r3.PeekValue(true).GetFirstChar()); } DataContext.SaveChanges(); tree.DataSource = DataContext.DepotRoleLoad(Depot.Id).ToList(); tree.DataBind(); var node = tree.GetAllNodes().ToList().First(o => o.Value == id.ToString()); node.Selected = true; } else { var role = new DepotRole { Id = DataContext.GlobalId(), DepotId = Depot.Id, Name = content, Rights = "{0}{1}{2}".Formatted(r1.PeekValue(true).GetFirstChar(), r2.PeekValue(true).GetFirstChar(), r3.PeekValue(true).GetFirstChar()), Ordinal = ordinal.PeekValue(100), State = State.启用 }; DataContext.DepotRole.Add(role); DataContext.SaveChanges(); tree.DataSource = DataContext.DepotRoleLoad(Depot.Id).ToList(); tree.DataBind(); var node = tree.GetAllNodes().ToList().First(o => o.Value == role.Id.ToString()); node.Selected = true; tree0.Nodes[0].Selected = false; InitializeArea(); } NotifyOK(ap, "角色保存成功"); }
public static void DepotRoleAddOrUpdate(this DepotEntities db, Guid depotId, Guid id, string name, string rights, int ordinal) { var count = db.DepotRoleLoad(depotId).Count(o => o.Id == id); if (count == 0) { var role = new DepotRole { Id = id, DepotId = depotId, Name = name, Rights = rights, Ordinal = ordinal, State = State.启用 }; db.DepotRole.Add(role); } else { var role = db.DepotRoleLoad(depotId).Single(o => o.Id == id); role.Name = name; role.Rights = rights; role.Ordinal = ordinal; } db.SaveChanges(); }
public static void DepotAdd(this DepotEntities db, string name, Guid campusId, Guid userId, int ordinal, string defaultObjectView, string defaultObjectType, string objectTypes) { var depot = new Depot { Id = db.GlobalId(), Name = name, CampusId = campusId, Ordinal = ordinal, DefaultObjectView = defaultObjectView[0].ToString(), DefaultObjectType = defaultObjectType[0].ToString(), ObjectTypes = objectTypes, Type = DepotType.通用库, State = State.启用 }; db.Depot.Add(depot); var depotRole = new DepotRole { Id = db.GlobalId(), DepotId = depot.Id, Name = "{0}管理组".Formatted(name), Rights = "*", Ordinal = 0, State = State.内置 }; db.DepotRole.Add(depotRole); var depotUserRole = new DepotUserRole { UserId = userId, DepotRoleId = depotRole.Id }; db.DepotUserRole.Add(depotUserRole); db.SaveChanges(); }