static void CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, string[] nodes, IDbConnection ctx, IDbTransaction txn, string chatPrefix = null, string chatSuffix = null) #endif { #if ENTITY_FRAMEWORK_7 var grp = new Group() { Name = name, ApplyToGuests = guest, Parent = parent, Chat_Red = r, Chat_Green = g, Chat_Blue = b, Chat_Prefix = chatPrefix, Chat_Suffix = chatSuffix }; ctx.Groups.Add(grp); ctx.SaveChanges(); //Save to get the ID foreach (var nd in nodes) { var node = ctx.Nodes.SingleOrDefault(x => x.Node == nd && x.Permission == Permission.Permitted); if (node == null) { ctx.Nodes.Add(node = new NodePermission() { Node = nd, Permission = Permission.Permitted }); ctx.SaveChanges(); } ctx.GroupNodes.Add(new GroupNode() { GroupId = grp.Id, NodeId = node.Id }); } ctx.SaveChanges(); #elif DAPPER var grp = new Group() { Name = name, ApplyToGuests = guest, Parent = parent, Chat_Red = r, Chat_Green = g, Chat_Blue = b, Chat_Prefix = chatPrefix, Chat_Suffix = chatSuffix }; grp.Id = ctx.Insert(grp, txn); foreach (var nd in nodes) { var node = ctx.SingleOrDefault<PermissionNode>(new { Node = nd, Permission = Permission.Permitted }, transaction: txn); if (node == null) { node = new PermissionNode() { Node = nd, Permission = Permission.Permitted }; node.Id = ctx.Insert(node, transaction: txn); } ctx.Insert(new GroupNode() { GroupId = grp.Id, NodeId = node.Id }, transaction: txn); } #endif }
static void CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, string[] nodes, TContext ctx, string chatPrefix = null, string chatSuffix = null) { var grp = new Group() { Name = name, ApplyToGuests = guest, Parent = parent, Chat_Red = r, Chat_Green = g, Chat_Blue = b, Chat_Prefix = chatPrefix, Chat_Suffix = chatSuffix }; ctx.Groups.Add(grp); ctx.SaveChanges(); //Save to get the ID foreach (var nd in nodes) { var node = ctx.Nodes.SingleOrDefault(x => x.Node == nd && x.Permission == Permission.Permitted); if (node == null) { ctx.Nodes.Add(node = new NodePermission() { Node = nd, Permission = Permission.Permitted }); ctx.SaveChanges(); } ctx.GroupNodes.Add(new GroupNode() { GroupId = grp.Id, NodeId = node.Id }); } ctx.SaveChanges(); }