Exemplo n.º 1
0
        public ActionResult EditPost(TenantEditViewModel viewModel) {
            try {
                if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't edit tenant")))
                    return new HttpUnauthorizedResult();

                var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);
                if (tenant == null)
                    return new NotFoundResult();
                
                _tenantService.UpdateTenant(
                    new ShellSettings {
                        Name = tenant.Name,
                        RequestUrlHost = viewModel.RequestUrlHost,
                        RequestUrlPrefix = viewModel.RequestUrlPrefix,
                        DataProvider = viewModel.DataProvider,
                        DataConnectionString = viewModel.DatabaseConnectionString,
                        DataTablePrefix = viewModel.DatabaseTablePrefix,
                        State = tenant.State
                    });

                return RedirectToAction("Index");
            }
            catch (Exception exception) {
                Services.Notifier.Error(T("Failed to edit tenant: ") + exception.Message);
                return View(viewModel);
            }
        }
Exemplo n.º 2
0
        public ActionResult EditPost(TenantEditViewModel viewModel) {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("You don't have permission to edit tenants.")))
                return new HttpUnauthorizedResult();

            if (!IsExecutingInDefaultTenant())
                return new HttpUnauthorizedResult();

            var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);

            if (tenant == null)
                return HttpNotFound();

            if (!ModelState.IsValid) {
                return View(viewModel);
            }

            try {
                _tenantService.UpdateTenant(
                    new ShellSettings(tenant) {
                        Name = tenant.Name,
                        RequestUrlHost = viewModel.RequestUrlHost,
                        RequestUrlPrefix = viewModel.RequestUrlPrefix,
                        DataProvider = viewModel.DataProvider,
                        DataConnectionString = viewModel.DatabaseConnectionString,
                        DataTablePrefix = viewModel.DatabaseTablePrefix,
                        State = tenant.State,
                        EncryptionAlgorithm = tenant.EncryptionAlgorithm,
                        EncryptionKey = tenant.EncryptionKey,
                        HashAlgorithm = tenant.HashAlgorithm,
                        HashKey = tenant.HashKey,
                        Themes = viewModel.Themes.Where(x => x.Checked).Select(x => x.ThemeId).ToArray(),
                        Modules = viewModel.Modules.Where(x => x.Checked).Select(x => x.ModuleId).ToArray()
                    });

                return RedirectToAction("Index");
            }
            catch (Exception ex) {
                Logger.Error(ex, "Error while editing tenant.");
                Services.Notifier.Error(T("Failed to edit tenant: {0} ", ex.Message));
                return View(viewModel);
            }
        }
        public ActionResult EditPost(TenantEditViewModel viewModel) {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Couldn't edit tenant")))
                return new HttpUnauthorizedResult();

            if ( !EnsureDefaultTenant() )
                return new HttpUnauthorizedResult();

            var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);
            if (tenant == null)
                return HttpNotFound();

            if (!ModelState.IsValid) {
                return View(viewModel);
            }

            try {
                _tenantService.UpdateTenant(
                    new ShellSettings {
                        Name = tenant.Name,
                        RequestUrlHost = viewModel.RequestUrlHost,
                        RequestUrlPrefix = viewModel.RequestUrlPrefix,
                        DataProvider = viewModel.DataProvider,
                        DataConnectionString = viewModel.DatabaseConnectionString,
                        DataTablePrefix = viewModel.DatabaseTablePrefix,
                        State = tenant.State,
                        EncryptionAlgorithm = tenant.EncryptionAlgorithm,
                        EncryptionKey = tenant.EncryptionKey,
                        HashAlgorithm = tenant.HashAlgorithm,
                        HashKey = tenant.HashKey
                    });

                return RedirectToAction("Index");
            }
            catch (Exception exception) {
                this.Error(exception, T("Failed to edit tenant: {0} ", exception.Message), Logger, Services.Notifier);
                return View(viewModel);
            }
        }