- CreateTenant on the service and related simple admin UI.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-04-21 15:43:41 -07:00
parent c0fac8d2ca
commit ed6b6a879e
7 changed files with 69 additions and 17 deletions

View File

@@ -8,7 +8,7 @@ namespace Orchard.MultiTenancy {
builder.Add("MultiTenancy", "2",
menu => menu
.Add("Manage Tenants", "1.0", item => item.Action("List", "Admin", new { area = "Orchard.MultiTenancy" }).Permission(Permissions.ManageTenants))
);
.Add("Add New Tenant", "1.1", item => item.Action("Add", "Admin", new { area = "Orchard.MultiTenancy" }).Permission(Permissions.ManageTenants)));
}
}
}

View File

@@ -1,19 +1,24 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using Orchard.Environment.Configuration;
using Orchard.Localization;
using Orchard.MultiTenancy.Services;
using Orchard.MultiTenancy.ViewModels;
using Orchard.UI.Notify;
namespace Orchard.MultiTenancy.Controllers {
[ValidateInput(false)]
public class AdminController : Controller {
private readonly ITenantService _tenantService;
public AdminController(ITenantService tenantService) {
public AdminController(ITenantService tenantService, IOrchardServices orchardServices) {
_tenantService = tenantService;
Services = orchardServices;
T = NullLocalizer.Instance;
}
private Localizer T { get; set; }
public IOrchardServices Services { get; set; }
public ActionResult List() {
return View(new TenantsListViewModel { TenantSettings = _tenantService.GetTenants() });
@@ -22,5 +27,28 @@ namespace Orchard.MultiTenancy.Controllers {
public ActionResult Add() {
return View(new TenantsAddViewModel());
}
[HttpPost, ActionName("Add")]
public ActionResult AddPOST() {
var viewModel = new TenantsAddViewModel();
try {
UpdateModel(viewModel);
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't create tenant")))
return new HttpUnauthorizedResult();
_tenantService.CreateTenant(
new ShellSettings {
Name = viewModel.Name,
DataProvider = viewModel.DataProvider,
DataConnectionString = viewModel.ConnectionString,
DataPrefix = viewModel.Prefix
});
return RedirectToAction("List");
}
catch (Exception exception) {
Services.Notifier.Error(T("Creating Tenant failed: ") + exception.Message);
return View(viewModel);
}
}
}
}

View File

@@ -32,6 +32,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>

View File

@@ -4,5 +4,6 @@ using Orchard.Environment.Configuration;
namespace Orchard.MultiTenancy.Services {
public interface ITenantService : IDependency {
IEnumerable<ShellSettings> GetTenants();
void CreateTenant(ShellSettings settings);
}
}

View File

@@ -15,6 +15,10 @@ namespace Orchard.MultiTenancy.Services {
return _shellSettingsManager.LoadSettings();
}
public void CreateTenant(ShellSettings settings) {
_shellSettingsManager.SaveSettings(settings);
}
#endregion
}
}

View File

@@ -1,6 +1,15 @@
using Orchard.Mvc.ViewModels;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Orchard.Mvc.ViewModels;
namespace Orchard.MultiTenancy.ViewModels {
public class TenantsAddViewModel : BaseViewModel {
[Required, DisplayName("Tenant Name:")]
public string Name { get; set; }
[Required]
public string DataProvider { get; set; }
public string ConnectionString { get; set; }
public string Prefix { get; set; }
}
}

View File

@@ -1,15 +1,22 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<TenantsAddViewModel>" %>
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<TenantsAddViewModel>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Add a new Tenant</title>
</head>
<body>
<div>
Add tenant...
</div>
</body>
</html>
<h1><%=Html.TitleForPage(T("Add a Tenant to your Site").ToString()) %></h1>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%= Html.ValidationSummary() %>
<fieldset>
<label for="Name"><%=_Encoded("Tenant Name") %></label>
<input id="Name" class="textMedium" name="Name" type="text" /><br />
<label for="DataProvider"><%=_Encoded("Data Provider Name") %></label>
<input id="DataProvider" class="textMedium" name="DataProvider" type="text" /><br />
<label for="Name"><%=_Encoded("Connection String") %></label>
<input id="ConnectionString" class="textMedium" name="ConnectionString" type="text" /><br />
<label for="Name"><%=_Encoded("Prefix") %></label>
<input id="Prefix" class="textMedium" name="Prefix" type="text" /><br />
</fieldset>
<fieldset>
<input type="submit" class="button primaryAction" value="<%=_Encoded("Save") %>" />
</fieldset>
<% } %>