コード例 #1
0
        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 */));
        }
コード例 #2
0
        public async Task UpdateUserPreferences()
        {
            var userName = "******";
            var bio      = Guid.NewGuid().ToString();
            var user     = TestHelper.SetPrincipal(userName);

            var q     = new QueryUserPreferences(userName).SetUserContext(user);
            var prefs = await q.ExecuteAsync();

            Assert.IsNotNull(prefs, "Pref query returned null");
            Assert.AreNotEqual(prefs.Bio, bio, "Bio returned unexpected data");

            var cmd = new UpdateUserPreferencesCommand(new Domain.Models.UserPreferenceUpdate()
            {
                Bio = bio
            }).SetUserContext(user);
            var r = await cmd.Execute();

            VoatAssert.IsValid(r);

            q     = new QueryUserPreferences(userName).SetUserContext(user);
            prefs = await q.ExecuteAsync();

            Assert.IsNotNull(prefs, "Pref requery returned null");
            Assert.AreEqual(prefs.Bio, bio, "Bio not updated");
        }
コード例 #3
0
        public async Task <ActionResult> ToggleNightMode()
        {
            var q = new QueryUserPreferences().SetUserContext(User);

            Task <Domain.Models.UserPreference> taskPreferences;

            taskPreferences = q.ExecuteAsync();
            Domain.Models.UserPreference lpreferences;
            lpreferences = await taskPreferences;

            UserPreferenceUpdate newPreferences;

            newPreferences = new Domain.Models.UserPreferenceUpdate();

            Domain.Models.UserPreference preferences;
            preferences = lpreferences;
            newPreferences.NightMode = !preferences.NightMode;

            var cmd = new UpdateUserPreferencesCommand(newPreferences).SetUserContext(User);
            Task <CommandResponse> taskResult;

            taskResult = cmd.Execute();
            CommandResponse result;

            result = await taskResult;

            string newTheme = newPreferences.NightMode.Value ? "dark" : "light";

            UserHelper.SetUserStylePreferenceCookie(HttpContext, newTheme);
            _statuscode         = 200;
            Response.StatusCode = _statuscode;
            return(Json("Toggled Night Mode" /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */));
        }
コード例 #4
0
        public async Task UpdateUserPreferences()
        {
            var userName = "******";
            var bio      = Guid.NewGuid().ToString();

            TestHelper.SetPrincipal(userName);

            var q     = new QueryUserPreferences(userName);
            var prefs = await q.ExecuteAsync();

            Assert.IsNotNull(prefs, "Pref query returned null");
            Assert.AreNotEqual(prefs.Bio, bio, "Bio returned unexpected data");

            var cmd = new UpdateUserPreferencesCommand(new Domain.Models.UserPreference()
            {
                Bio = bio
            });
            var result = await cmd.Execute();

            Assert.IsNotNull(result, "UpdatePref command returned null");
            Assert.AreEqual(true, result.Success, "UpdatePref command returned non success");

            q     = new QueryUserPreferences(userName);
            prefs = await q.ExecuteAsync();

            Assert.IsNotNull(prefs, "Pref requery returned null");
            Assert.AreEqual(prefs.Bio, bio, "Bio not updated");
        }
コード例 #5
0
        private static async Task <bool> UserAllowsAnonMentions(string userName, bool isAnonymized)
        {
            var allowed = true;

            if (isAnonymized)
            {
                var q     = new QueryUserPreferences(userName);
                var prefs = await q.ExecuteAsync();

                allowed = !prefs.BlockAnonymized;
            }
            return(allowed);
        }
コード例 #6
0
        public async Task Query_UserPreferences_Default()
        {
            var q      = new QueryUserPreferences();
            var result = await q.ExecuteAsync();

            Assert.IsNotNull(result);
            Assert.AreEqual("en", result.Language);

            q      = new QueryUserPreferences();
            result = await q.ExecuteAsync();

            Assert.IsNotNull(result, this.GetType().Name);
            Assert.AreEqual("en", result.Language, this.GetType().Name);
        }