using Microsoft.EntityFrameworkCore; using Shadow.Data; using Shadow.Entities; using System.Text; namespace Shadow.Tools; public class GeneralUseHelpers(ApplicationDbContext? db = null, IConfiguration? appsettings = null) { private readonly ApplicationDbContext? _db = db; private readonly IConfiguration? _appsettings = appsettings; //async public Task GetUserFromEmail(string email) //{ // return await _db.Users.FirstOrDefaultAsync(e => e.Email == email); //} //public string HashWithSHA512(string s) //{ // using (var sha512 = SHA512.Create()) // { // byte[] bytes = Encoding.ASCII.GetBytes(s); // byte[] hash = sha512.ComputeHash(bytes); // string hashstring = BitConverter.ToString(hash).Replace("-", "").ToLower(); // return hashstring; // } //} /// /// Quick and dirty Dictionary<string, string> to JSON serializer /// /// Dictionary with keypair of two strings /// Minified JSON public static string DictAsJson(Dictionary dict) { string resultJson = String.Empty; foreach (string key in dict.Keys) { string cleanKey = key.Replace("\"", "\\\""); // "a"b" -> "a\"b" string cleanValue = dict[key].Replace("\"", "\\\""); resultJson += $"\"{cleanKey}\": \"{cleanValue}\", " // "key": "val", .Replace(@"\", @"\\"); // a\b -> a\\b } return "{" + resultJson[..^2] + "}"; } }