public async Task <ActionResult <TSReaction> > AddReaction([FromBody] TSReaction TSReaction) { TSReaction.UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10); await TS.AddActivityLog(TSReaction.UserID, "Add or update Reaction", MethodBase.GetCurrentMethod()); string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10); if (!string.IsNullOrEmpty(TSReaction.UserID)) { if (userName.Equals("demouser")) { return(new TSReaction()); } } TSReactionEntity oldReaction = await TS.FindReaction(TSReaction.UserID, true, string.Empty); if (oldReaction is null) { string a = await TS.GetNewID("AllUsers", "LastReactionID", false); TSReaction.ReactionID = int.Parse(a); bool b = await TS.AddReaction(TSReaction); if (b) { await GlobalFunctions.NotifyAdmin("New Reaction " + userName + " " + TSReaction.LikeOrDislike); if (TSReaction.LikeOrDislike) { await TS.UpdateSettingCounter("AllUsers", "LikesCount", true); } else { await TS.UpdateSettingCounter("AllUsers", "DislikesCount", true); } } } else { if (oldReaction.LikeOrDislike != TSReaction.LikeOrDislike) { if (oldReaction.LikeOrDislike) { await TS.UpdateSettingCounter("AllUsers", "LikesCount", false); } else { await TS.UpdateSettingCounter("AllUsers", "DislikesCount", false); } bool b = await TS.UpdateReaction(TSReaction); if (b) { await GlobalFunctions.NotifyAdmin("Reaction update to " + TSReaction.LikeOrDislike + " " + userName); if (TSReaction.LikeOrDislike) { await TS.UpdateSettingCounter("AllUsers", "LikesCount", true); } else { await TS.UpdateSettingCounter("AllUsers", "DislikesCount", true); } } } } SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV { Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5), IV = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10) }; if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key)) { TSReactionEntity reactionEntity = await TS.FindReaction(TSReaction.UserID, true, string.Empty); if (reactionEntity != null) { TSReaction result = reactionEntity.toTSReaction(); GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV); return(result); } else { return(new TSReaction()); } } else { return(new TSReaction()); } }