public async Task <ActionResult> ToggleNightMode() { var q = new QueryUserPreferences().SetUserContext(User); var preferences = await q.ExecuteAsync(); var newPreferences = new Domain.Models.UserPreferenceUpdate(); newPreferences.NightMode = !preferences.NightMode; var cmd = new UpdateUserPreferencesCommand(newPreferences).SetUserContext(User); var result = await cmd.Execute(); string newTheme = newPreferences.NightMode.Value ? "dark" : "light"; //// save changes //using (var db = new VoatUIDataContextAccessor()) //{ // var userPreferences = GetUserPreference(db); // userPreferences.NightMode = !userPreferences.NightMode; // await db.SaveChangesAsync(); // newTheme = userPreferences.NightMode ? "dark" : "light"; //} UserHelper.SetUserStylePreferenceCookie(HttpContext, newTheme); Response.StatusCode = 200; return(Json("Toggled Night Mode" /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */)); }
public async Task <ActionResult> UserPreferences(Domain.Models.UserPreferenceUpdate model) { ViewBag.UserName = User.Identity.Name; if (!ModelState.IsValid) { return(View("Manage", model)); } var cmd = new UpdateUserPreferencesCommand(model).SetUserContext(User); var result = await cmd.Execute(); if (result.Success) { var newTheme = model.NightMode.Value ? "dark" : "light"; UserHelper.SetUserStylePreferenceCookie(HttpContext, newTheme); } //// save changes //string newTheme; //using (var db = new VoatUIDataContextAccessor()) //{ // var userPreferences = GetUserPreference(db); // // modify existing preferences // userPreferences.DisableCSS = model.Disable_custom_css; // userPreferences.NightMode = model.Night_mode; // userPreferences.OpenInNewWindow = model.OpenLinksInNewTab; // userPreferences.EnableAdultContent = model.Enable_adult_content; // userPreferences.DisplaySubscriptions = model.Public_subscriptions; // userPreferences.UseSubscriptionsMenu = model.Topmenu_from_subscriptions; // await db.SaveChangesAsync(); // newTheme = userPreferences.NightMode ? "dark" : "light"; //} //ClearUserCache(); //UserHelper.SetUserStylePreferenceCookie(newTheme); return(RedirectToAction("Manage")); }
public UpdateUserPreferencesCommand(Domain.Models.UserPreferenceUpdate preferences) { _preferences = preferences; }