public static void Remove(Blacklist row) { using ContraCoreDBContext contraDB = new ContraCoreDBContext(); var match = contraDB.blacklist.SingleOrDefault(v => v.id == row.ID); contraDB.blacklist.Remove(match); contraDB.SaveChanges(); }
public static void Submit(Blacklist newRule) { using ContraCoreDBContext contraDB = new ContraCoreDBContext(); contraDB.blacklist.Add(new blacklist { pattern = newRule.Pattern, expires = newRule.Expires, _class = 0, }); contraDB.SaveChanges(); }
public static bool Update(Config config) { using ContraCoreDBContext contraDB = new ContraCoreDBContext(); Config?current = Read(); if (current != null) { if (current.ToString() == config.ToString()) { Common.Logger.Info( "The latest config in the database matches the new config passed to ConfigController.Update(); not storing new config.", new Fields { { "Config", config.ToString() } } ); return(true); } } Common.Logger.Info( "Storing new config in database.", new Fields { { "Config", config.ToString() } } ); contraDB.config.Add(new config { id = 0, sources = config.Sources.ToArray(), search_domains = config.SearchDomains.ToArray(), domain_needed = config.DomainNeeded, spoofed_a = config.SpoofedA, spoofed_aaaa = config.SpoofedAAAA, spoofed_cname = config.SpoofedCNAME, spoofed_default = config.SpoofedDefault }); contraDB.SaveChanges(); return(true); }
public static void Submit(Whitelist whitelist) { using ContraCoreDBContext contraDB = new ContraCoreDBContext(); whitelist dbWhitelist = new whitelist { pattern = whitelist.Pattern, expires = whitelist.Expires, ips = whitelist.IPs?.ToArray(), subnets = whitelist.Subnets? .Select(v => new ValueTuple <IPAddress, int>(v.Network, v.Cidr)) .ToArray(), hostnames = whitelist.Hostnames?.ToArray(), macs = whitelist.MACs?.ToArray(), vendors = whitelist.Vendors?.ToArray() }; contraDB.Add(dbWhitelist); contraDB.SaveChanges(); whitelist.ID = dbWhitelist.id; }
public static void Update(Whitelist whitelist) { using ContraCoreDBContext contraDB = new ContraCoreDBContext(); whitelist?match = contraDB.whitelist.SingleOrDefault(v => v.id == whitelist.ID); if (match == null) { throw new ArgumentException($"Could not find whitelist rule with ID '{whitelist.ID}'"); } match.pattern = whitelist.Pattern; match.expires = whitelist.Expires; match.ips = whitelist.IPs?.ToArray(); match.subnets = whitelist.Subnets? .Select(v => new ValueTuple <IPAddress, int>(v.Network, v.Cidr)) .ToArray(); match.hostnames = whitelist.Hostnames?.ToArray(); match.macs = whitelist.MACs?.ToArray(); match.vendors = whitelist.Vendors?.ToArray(); contraDB.Update(match); contraDB.SaveChanges(); }