Exemple #1
0
        protected virtual async Task <CodeZeroUserNavConfigDto> GetUserNavConfig()
        {
            var userMenus = await UserNavigationManager.GetMenusAsync(CodeZeroSession.ToUserIdentifier());

            return(new CodeZeroUserNavConfigDto
            {
                Menus = userMenus.ToDictionary(userMenu => userMenu.Name, userMenu => userMenu)
            });
        }
        public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new CodeZeroException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName));

            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                cookieValue,
                new CookieOptions
            {
                Expires  = Clock.Now.AddYears(2),
                HttpOnly = true
            }
                );

            if (CodeZeroSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    CodeZeroSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                    );
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new AjaxResponse()));
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && CodeZeroUrlHelper.IsLocalUrl(Request, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect("/")); //TODO: Go to app root
        }
Exemple #3
0
        public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new CodeZeroException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            Response.Cookies.Add(
                new HttpCookie(_webLocalizationConfiguration.CookieName, cultureName)
            {
                Expires = Clock.Now.AddYears(2),
                Path    = Request.ApplicationPath
            }
                );

            if (CodeZeroSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    CodeZeroSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                    );
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && CodeZeroUrlHelper.IsLocalUrl(Request.Url, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect(Request.ApplicationPath));
        }
        /// <inheritdoc/>
        public async Task <IReadOnlyList <ISettingValue> > GetAllSettingValuesAsync(SettingScopes scopes)
        {
            var settingDefinitions = new Dictionary <string, SettingDefinition>();
            var settingValues      = new Dictionary <string, ISettingValue>();

            //Fill all setting with default values.
            foreach (var setting in _settingDefinitionManager.GetAllSettingDefinitions())
            {
                settingDefinitions[setting.Name] = setting;
                settingValues[setting.Name]      = new SettingValueObject(setting.Name, setting.DefaultValue);
            }

            //Overwrite application settings
            if (scopes.HasFlag(SettingScopes.Application))
            {
                foreach (var settingValue in await GetAllSettingValuesForApplicationAsync())
                {
                    var setting = settingDefinitions.GetOrDefault(settingValue.Name);

                    //TODO: Conditions get complicated, try to simplify it
                    if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Application))
                    {
                        continue;
                    }

                    if (!setting.IsInherited &&
                        ((setting.Scopes.HasFlag(SettingScopes.Tenant) && CodeZeroSession.TenantId.HasValue) || (setting.Scopes.HasFlag(SettingScopes.User) && CodeZeroSession.UserId.HasValue)))
                    {
                        continue;
                    }

                    settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value);
                }
            }

            //Overwrite tenant settings
            if (scopes.HasFlag(SettingScopes.Tenant) && CodeZeroSession.TenantId.HasValue)
            {
                foreach (var settingValue in await GetAllSettingValuesForTenantAsync(CodeZeroSession.TenantId.Value))
                {
                    var setting = settingDefinitions.GetOrDefault(settingValue.Name);

                    //TODO: Conditions get complicated, try to simplify it
                    if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Tenant))
                    {
                        continue;
                    }

                    if (!setting.IsInherited &&
                        (setting.Scopes.HasFlag(SettingScopes.User) && CodeZeroSession.UserId.HasValue))
                    {
                        continue;
                    }

                    settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value);
                }
            }

            //Overwrite user settings
            if (scopes.HasFlag(SettingScopes.User) && CodeZeroSession.UserId.HasValue)
            {
                foreach (var settingValue in await GetAllSettingValuesForUserAsync(CodeZeroSession.ToUserIdentifier()))
                {
                    var setting = settingDefinitions.GetOrDefault(settingValue.Name);
                    if (setting != null && setting.Scopes.HasFlag(SettingScopes.User))
                    {
                        settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value);
                    }
                }
            }

            return(settingValues.Values.ToImmutableList());
        }