예제 #1
0
        public virtual ActionResult MainSettings()
        {
            var handler = AppCore.Get <ModuleControllerTypesManager>();
            var model   = new Model.AdminMainModelInfoPage(AppCore.AppConfig, AppCore.WebConfig)
            {
                ModulesList = (from p in AppCore.GetModulesManager().GetModules()
                               where handler.GetModuleControllerTypes(p.QueryType) != null
                               orderby p.Caption
                               select new SelectListItem()
                {
                    Value = p.ID.ToString(),
                    Text = p.Caption,
                    Selected = AppCore.WebConfig.IdModuleDefault == p.ID
                }).ToList()
            };

            using (var db = Module.CreateUnitOfWork())
            {
                model.Roles = (from p in db.Role orderby p.NameRole ascending select p).ToList();
                model.Roles.Insert(0, new Role()
                {
                    IdRole = 0, NameRole = "Не выбрано"
                });
            }

            return(View("CoreSettings.tpl", model));
        }
예제 #2
0
        public virtual JsonResult MainSettingsSave(Model.AdminMainModelInfoPage model)
        {
            var result = JsonAnswer();
            CoreConfiguration <WebApplication> cfgAppOld = null;
            WebCoreConfiguration cfgWebOld = null;

            try
            {
                if (ModelState.IsValid)
                {
                    cfgAppOld = AppCore.AppCoreModule.GetConfigurationManipulator().GetEditable <CoreConfiguration <WebApplication> >();
                    cfgWebOld = AppCore.GetModulesManager().GetModule <WebCoreModule>().GetConfigurationManipulator().GetEditable <WebCoreConfiguration>();

                    var cfgApp = AppCore.GetModulesManager().GetModule <CoreModule <WebApplication> >().GetConfigurationManipulator().GetEditable <CoreConfiguration <WebApplication> >();
                    cfgApp.RoleGuest = model.AppCoreConfiguration.RoleGuest;
                    cfgApp.RoleUser  = model.AppCoreConfiguration.RoleUser;

                    var applyResult = AppCore.GetModulesManager().GetModule <CoreModule <WebApplication> >().GetConfigurationManipulator().ApplyConfiguration(cfgApp);
                    switch (applyResult.Item1)
                    {
                    case ApplyConfigurationResult.PermissionDenied:
                        result.Message = "Недостаточно прав для сохранения конфигурации системы.";
                        result.Success = false;
                        break;

                    case ApplyConfigurationResult.Failed:
                        var journalData = AppCore.Get <JournalingManager>().GetJournalData(applyResult.Item2.Value);
                        result.Message = $"Возникла ошибка при сохранении настроек: {(journalData?.Message ?? "текст ошибки не найден")}.";
                        result.Success = false;
                        break;

                    case ApplyConfigurationResult.Success:
                        System.Web.Routing.RouteTable.Routes.Where(x => x is RouteWithDefaults).Select(x => x as RouteWithDefaults).ForEach(x => x.UpdateDefaults());

                        result.Message = "Сохранено успешно!";
                        result.Success = true;
                        break;
                    }

                    if (result.Success)
                    {
                        var cfg = AppCore.GetModulesManager().GetModule <WebCoreModule>().GetConfigurationManipulator().GetEditable <WebCoreConfiguration>();
                        cfg.IdModuleDefault       = model.WebCoreConfiguration.IdModuleDefault;
                        cfg.DeveloperEmail        = model.WebCoreConfiguration.DeveloperEmail;
                        cfg.SiteFullName          = model.WebCoreConfiguration.SiteFullName;
                        cfg.ContactEmail          = model.WebCoreConfiguration.ContactEmail;
                        cfg.ReturnEmail           = model.WebCoreConfiguration.ReturnEmail;
                        cfg.CriticalMessagesEmail = model.WebCoreConfiguration.CriticalMessagesEmail;
                        cfg.register_mode         = model.WebCoreConfiguration.register_mode;
                        cfg.site_reginfo          = model.WebCoreConfiguration.site_reginfo;
                        cfg.site_loginfo          = model.WebCoreConfiguration.site_loginfo;
                        cfg.help_info             = model.WebCoreConfiguration.help_info;
                        cfg.site_descr            = model.WebCoreConfiguration.site_descr;
                        cfg.site_keys             = model.WebCoreConfiguration.site_keys;

                        cfg.userAuthorizeAllowed = model.WebCoreConfiguration.userAuthorizeAllowed;

                        applyResult = AppCore.GetModulesManager().GetModule <WebCoreModule>().GetConfigurationManipulator().ApplyConfiguration(cfg);
                        switch (applyResult.Item1)
                        {
                        case ApplyConfigurationResult.PermissionDenied:
                            result.Message = "Недостаточно прав для сохранения конфигурации системы.";
                            result.Success = false;
                            break;

                        case ApplyConfigurationResult.Failed:
                            var journalData = AppCore.Get <JournalingManager>().GetJournalData(applyResult.Item2.Value);
                            result.Message = $"Возникла ошибка при сохранении настроек: {(journalData?.Message ?? "текст ошибки не найден")}.";
                            result.Success = false;
                            break;

                        case ApplyConfigurationResult.Success:
                            System.Web.Routing.RouteTable.Routes.Where(x => x is RouteWithDefaults).Select(x => x as RouteWithDefaults).ForEach(x => x.UpdateDefaults());

                            result.Message = "Сохранено успешно!";
                            result.Success = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            try
            {
                if (!result.Success)
                {
                    if (cfgAppOld != null)
                    {
                        AppCore.GetModulesManager().GetModule <CoreModule <WebApplication> >().GetConfigurationManipulator().ApplyConfiguration(cfgAppOld);
                    }
                    if (cfgWebOld != null)
                    {
                        AppCore.GetModulesManager().GetModule <WebCoreModule>().GetConfigurationManipulator().ApplyConfiguration(cfgWebOld);
                    }
                }
            }
            catch { }

            return(this.ReturnJson(result));
        }