public bool ToggleExcludeChannel(ulong guildId, ulong chId) { var channels = _excludedChannels.GetOrAdd(guildId, _ => new ConcurrentHashSet <ulong>()); using (var uow = _db.UnitOfWork) { var xpSetting = uow.GuildConfigs.XpSettingsFor(guildId); var excludeObj = new ExcludedItem { ItemId = chId, ItemType = ExcludedItemType.Channel, }; if (channels.Add(chId)) { if (xpSetting.ExclusionList.Add(excludeObj)) { uow.Complete(); } return(true); } else { channels.TryRemove(chId); if (xpSetting.ExclusionList.Remove(excludeObj)) { uow.Complete(); } return(false); } } }
public bool ToggleExcludeRole(ulong guildId, ulong rId) { var roles = _excludedRoles.GetOrAdd(guildId, _ => new ConcurrentHashSet<ulong>()); using (var uow = _db.UnitOfWork) { var xpSetting = uow.GuildConfigs.XpSettingsFor(guildId); var excludeObj = new ExcludedItem { ItemId = rId, ItemType = ExcludedItemType.Role, }; if (roles.Add(rId)) { if (xpSetting.ExclusionList.Add(excludeObj)) { uow.Complete(); } return true; } else { roles.TryRemove(rId); if (xpSetting.ExclusionList.Remove(excludeObj)) { uow.Complete(); } return false; } } }
public bool ToggleExcludeRole(ulong guildId, ulong rId) { var roles = _excludedRoles.GetOrAdd(guildId, _ => new ConcurrentHashSet <ulong>()); using (var uow = _db.UnitOfWork) { var xpSetting = uow.GuildConfigs.XpSettingsFor(guildId); var excludeObj = new ExcludedItem { ItemId = rId, ItemType = ExcludedItemType.Role, }; if (roles.Add(rId)) { if (xpSetting.ExclusionList.Add(excludeObj)) { uow.Complete(); } return(true); } else { roles.TryRemove(rId); var toDelete = xpSetting.ExclusionList.FirstOrDefault(x => x.Equals(excludeObj)); if (toDelete != null) { uow._context.Remove(toDelete); uow.Complete(); } return(false); } } }