public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State s) { using (var uow = _db.UnitOfWork) { var conf = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.DelMsgOnCmdChannels)); var obj = new DelMsgOnCmdChannel() { ChannelId = chId, State = s == Administration.State.Enable, }; conf.DelMsgOnCmdChannels.Remove(obj); if (s != Administration.State.Inherit) { conf.DelMsgOnCmdChannels.Add(obj); } await uow.CompleteAsync().ConfigureAwait(false); } if (s == Administration.State.Disable) { DeleteMessagesOnCommandChannels.AddOrUpdate(chId, false, delegate { return(false); }); } else if (s == Administration.State.Enable) { DeleteMessagesOnCommandChannels.AddOrUpdate(chId, true, delegate { return(true); }); } else { DeleteMessagesOnCommandChannels.TryRemove(chId, out var _); } }
public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State newState) { using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.DelMsgOnCmdChannels)); var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId); if (newState == Administration.State.Inherit) { if (!(old is null)) { conf.DelMsgOnCmdChannels.Remove(old); uow._context.Remove(old); } } else { if (old is null) { old = new DelMsgOnCmdChannel { ChannelId = chId }; conf.DelMsgOnCmdChannels.Add(old); } old.State = newState == Administration.State.Enable; DeleteMessagesOnCommandChannels[chId] = newState == Administration.State.Enable; } await uow.SaveChangesAsync(); } if (newState == Administration.State.Disable) { } else if (newState == Administration.State.Enable) { DeleteMessagesOnCommandChannels[chId] = true; } else { DeleteMessagesOnCommandChannels.TryRemove(chId, out var _); } }
public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State s) { using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.DelMsgOnCmdChannels)); var obj = new DelMsgOnCmdChannel() { ChannelId = chId, State = s == Administration.State.Enable, }; var del = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.Equals(obj)); if (s != Administration.State.Inherit) { conf.DelMsgOnCmdChannels.Add(obj); } else { if (del != null) { uow._context.Remove(del); } } await uow.SaveChangesAsync(); } if (s == Administration.State.Disable) { DeleteMessagesOnCommandChannels.AddOrUpdate(chId, false, delegate { return(false); }); } else if (s == Administration.State.Enable) { DeleteMessagesOnCommandChannels.AddOrUpdate(chId, true, delegate { return(true); }); } else { DeleteMessagesOnCommandChannels.TryRemove(chId, out var _); } }