/// <summary>
        /// Saves  the M main object into the database.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="httpContext">The HTTP context.</param>
        /// <param name="main">The main.</param>
        public static void SaveDatabase(IConfiguration configuration, HttpContext httpContext, object main)
        {
            var  storageID = GetStorageID(main.GetType().Name);
            Guid session   = Guid.NewGuid(); // cannot exist in the database
            var  newCookie = new NameValueCollection();
            var  cookie    = httpContext.Request.Cookies[storageID].FromCookieString();

            if (cookie != null)
            {
                Guid.TryParse(cookie["session"], out session);
            }
            Func <byte[], byte[]> filter = null;

            if (StorageImplementation.GetEncryptDatabaseStorage(configuration))
            {
                var key    = (cookie["key"] != null) ? Convert.FromBase64String(cookie["key"]) : null;
                var secret = StorageImplementation.GetSecret(key);
                filter           = x => Crypt.Encrypt(secret, x);
                newCookie["key"] = Convert.ToBase64String(secret.Key);
            }
            using (var db = new ASP_DBEntities())
            {
                var savedSession = db.SaveMain(main.GetType(), StorageImplementation.Bytes(main, filter), session);
                newCookie["session"] = savedSession.ToString();
            }

            var days    = configuration.GetValue <int>("DatabaseStorageExpires");
            var options = new CookieOptions()
            {
                Expires  = DateTime.Now.AddDays(days),
                HttpOnly = true,
                SameSite = SameSiteMode.Strict
            };

            httpContext.Response.Cookies.Append(storageID, newCookie.ToCookieString(), options);
        }
        /// <summary>
        /// Saves the M main object into the session.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="httpContext">The HTTP context.</param>
        /// <param name="main">The main.</param>
        public static void SaveSession(IConfiguration configuration, HttpContext httpContext, object main)
        {
            var storageID = GetStorageID(main.GetType().Name);

            httpContext.Session.Set(storageID, StorageImplementation.Bytes(main));
        }