I hope I did not misunderstand your intentions, and the following code will give you some inspiration.
[ext-local-custom]
exten => 1234,1,Answer()
; Ask agent to input action
; 1 - enable DND
; 0 - disable DND
exten => 1234,n(input),Read(digito,enter-toggled-on-off,1)
exten => 1234,n,GotoIf($["foo${digito}"="foo1"]?toggledOn)
exten => 1234,n,GotoIf($["foo${digito}"="foo0"]?toggledOff)
exten => 1234,n,Playback(invalid)
exten => 1234,n,Goto(input)
exten => 1234,n(toggledOn),NoOP(section toggled On)
; Set DND ON
exten => 1234,n,Set(DB(DND/${CALLERID(number)})=YES)
; MySQL record action
exten => 1234,n,MySql(connect connid localhost root test)
exten => 1234,n,MySql(query resultidr ${connid} INSERT INTO `test`.`togglelog` (`exten`\,`toggle`\,`logtime`)VALUES (\'${CALLERID(number)}\'\,1\,\'${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)}\'))
exten => 1234,n,Goto(end)
exten => 1234,n(toggledOff),NoOP(section toggled Off)
; Set DND Off
exten => 1234,n,DBdel(DND/${CALLERID(number)})
; MySQL record action
exten => 1234,n,MySql(connect connid localhost root test)
exten => 1234,n,MySql(query resultidr ${connid} INSERT INTO `test`.`togglelog` (`exten`\,`toggle`\,`logtime`)VALUES (\'${CALLERID(number)}\'\,0\,\'${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)}\'))
exten => 1234,n,Goto(end)
exten => 1234,n(end),Hangup()