mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 19:49:51 +08:00
- Create/Read/Update/Delete actions for the Roles module.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4039504
This commit is contained in:
parent
51c4cec177
commit
eb9cfcbda2
@ -1,43 +1,94 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.Notify;
|
using Orchard.Notify;
|
||||||
using Orchard.Roles.Models;
|
using Orchard.Roles.Models;
|
||||||
|
using Orchard.Roles.Services;
|
||||||
using Orchard.Roles.ViewModels;
|
using Orchard.Roles.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Roles.Controllers {
|
namespace Orchard.Roles.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
private readonly IRepository<RoleRecord> _roleRepository;
|
private readonly IRoleService _roleService;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
|
||||||
public AdminController(IRepository<RoleRecord> roleRepository, INotifier notifier) {
|
public AdminController(IRoleService roleService, INotifier notifier) {
|
||||||
_roleRepository = roleRepository;
|
_roleService = roleService;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index() {
|
public ActionResult Index() {
|
||||||
var model = new RolesIndexViewModel {
|
var model = new RolesIndexViewModel { Rows = _roleService.GetRoles() as IList<RoleRecord> };
|
||||||
Rows = _roleRepository.Fetch(x => x.Name != null)
|
|
||||||
.Select(x => new RolesIndexViewModel.Row {
|
|
||||||
Role = x
|
|
||||||
})
|
|
||||||
.ToList()
|
|
||||||
};
|
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: NYI
|
[AcceptVerbs(HttpVerbs.Post)]
|
||||||
|
public ActionResult Index(FormCollection input) {
|
||||||
|
try {
|
||||||
|
foreach (string key in input.Keys) {
|
||||||
|
if (key.StartsWith("Checkbox.") && input[key] == "true") {
|
||||||
|
int roleId = Convert.ToInt32(key.Substring("Checkbox.".Length));
|
||||||
|
_roleService.DeleteRole(roleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
_notifier.Error("Deleting Role failed: " + exception.Message);
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult Create() {
|
public ActionResult Create() {
|
||||||
var model = new RoleCreateViewModel();
|
var model = new RoleCreateViewModel();
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: NYI
|
[AcceptVerbs(HttpVerbs.Post)]
|
||||||
|
public ActionResult Create(FormCollection input) {
|
||||||
|
var viewModel = new RoleCreateViewModel();
|
||||||
|
try {
|
||||||
|
UpdateModel(viewModel, input.ToValueProvider());
|
||||||
|
_roleService.CreateRole(viewModel.Name);
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
_notifier.Error("Creating Role failed: " + exception.Message);
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult Edit(int id) {
|
public ActionResult Edit(int id) {
|
||||||
var model = new RoleEditViewModel();
|
var role = _roleService.GetRole(id);
|
||||||
|
if (role == null) {
|
||||||
|
//TODO: Error message
|
||||||
|
throw new HttpException(404, "page with id " + id + " was not found");
|
||||||
|
}
|
||||||
|
var model = new RoleEditViewModel { Name = role.Name, Id = role.Id };
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AcceptVerbs(HttpVerbs.Post)]
|
||||||
|
public ActionResult Edit(FormCollection input) {
|
||||||
|
var viewModel = new RoleEditViewModel();
|
||||||
|
try {
|
||||||
|
UpdateModel(viewModel, input.ToValueProvider());
|
||||||
|
// Save
|
||||||
|
if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Save"])) {
|
||||||
|
_roleService.UpdateRole(viewModel.Id, viewModel.Name);
|
||||||
|
}
|
||||||
|
else if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Delete"])) {
|
||||||
|
_roleService.DeleteRole(viewModel.Id);
|
||||||
|
}
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
_notifier.Error("Editing media file failed: " + exception.Message);
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Models\RoleRecord.cs" />
|
<Compile Include="Models\RoleRecord.cs" />
|
||||||
<Compile Include="Models\RolesPermissions.cs" />
|
<Compile Include="Models\RolesPermissions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Services\RoleService.cs" />
|
||||||
<Compile Include="ViewModels\RoleCreateViewModel.cs" />
|
<Compile Include="ViewModels\RoleCreateViewModel.cs" />
|
||||||
<Compile Include="ViewModels\RoleEditViewModel.cs" />
|
<Compile Include="ViewModels\RoleEditViewModel.cs" />
|
||||||
<Compile Include="ViewModels\RolesIndexViewModel.cs" />
|
<Compile Include="ViewModels\RolesIndexViewModel.cs" />
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using Orchard.Mvc.ViewModels;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Roles.ViewModels {
|
namespace Orchard.Roles.ViewModels {
|
||||||
public class RoleCreateViewModel : AdminViewModel {
|
public class RoleCreateViewModel : AdminViewModel {
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
using Orchard.Mvc.ViewModels;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Roles.ViewModels {
|
namespace Orchard.Roles.ViewModels {
|
||||||
public class RoleEditViewModel : AdminViewModel {
|
public class RoleEditViewModel : AdminViewModel {
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,6 @@ using Orchard.Roles.Models;
|
|||||||
|
|
||||||
namespace Orchard.Roles.ViewModels {
|
namespace Orchard.Roles.ViewModels {
|
||||||
public class RolesIndexViewModel : AdminViewModel {
|
public class RolesIndexViewModel : AdminViewModel {
|
||||||
public class Row {
|
public IList<RoleRecord> Rows { get; set; }
|
||||||
public RoleRecord Role { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public IList<Row> Rows { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,13 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<% Html.Include("Header"); %>
|
<% Html.Include("Header"); %>
|
||||||
|
<% Html.BeginForm(); %>
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
<div class="yui-g">
|
<div class="yui-g">
|
||||||
<h2 class="separator">Add a Role</h2>
|
<h2 class="separator">Add a Role</h2>
|
||||||
<h3>Information</h3>
|
<h3>Information</h3>
|
||||||
<label for="pageTitle">Role Name:</label>
|
<label for="pageTitle">Role Name:</label>
|
||||||
<input id="pageTitle" class="inputText inputTextLarge" name="pageTitle" type="text" />
|
<input id="Name" class="inputText inputTextLarge" name="Name" type="text" value="<%= Model.Name %>" />
|
||||||
|
|
||||||
<h3>Permissions</h3>
|
<h3>Permissions</h3>
|
||||||
|
|
||||||
@ -43,9 +45,9 @@
|
|||||||
<td><input type="checkbox" value="" /></td>
|
<td><input type="checkbox" value="" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<input type="button" class="button" value="Save" />
|
<input type="submit" class="button" value="Save" />
|
||||||
<input type="button" class="button" value="Delete" />
|
|
||||||
</div>
|
</div>
|
||||||
|
<% Html.EndForm(); %>
|
||||||
<% Html.Include("Footer"); %>
|
<% Html.Include("Footer"); %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -10,12 +10,14 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<% Html.Include("Header"); %>
|
<% Html.Include("Header"); %>
|
||||||
|
<% Html.BeginForm(); %>
|
||||||
|
<%= Html.ValidationSummary() %>
|
||||||
<div class="yui-g">
|
<div class="yui-g">
|
||||||
<h2 class="separator">Edit a Role</h2>
|
<h2 class="separator">Edit a Role</h2>
|
||||||
<h3>Information</h3>
|
<h3>Information</h3>
|
||||||
<label for="pageTitle">Role Name:</label>
|
<label for="pageTitle">Role Name:</label>
|
||||||
<input id="pageTitle" class="inputText inputTextLarge" name="pageTitle" type="text" />
|
<input id="Name" class="inputText inputTextLarge" name="Name" type="text" value="<%=Model.Name %>"/>
|
||||||
|
<input type="hidden" value="<%= Model.Id %>" name="Id" />
|
||||||
<h3>Permissions</h3>
|
<h3>Permissions</h3>
|
||||||
|
|
||||||
<h4>Pages Module</h4>
|
<h4>Pages Module</h4>
|
||||||
@ -43,9 +45,10 @@
|
|||||||
<td><input type="checkbox" value="" /></td>
|
<td><input type="checkbox" value="" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<input type="button" class="button" value="Save" />
|
<input type="submit" class="button" name="submit.Save" value="Save" />
|
||||||
<input type="button" class="button" value="Delete" />
|
<input type="submit" class="button" name="submit.Delete" value="Delete" />
|
||||||
</div>
|
</div>
|
||||||
|
<% Html.EndForm(); %>
|
||||||
<% Html.Include("Footer"); %>
|
<% Html.Include("Footer"); %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -39,9 +39,9 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<%foreach (var row in Model.Rows) { %>
|
<%foreach (var row in Model.Rows) { %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="checkbox" value="true" name="<%= "Checkbox." + row.Role.Name %>"/></td>
|
<td><input type="checkbox" value="true" name="<%= "Checkbox." + row.Id %>"/></td>
|
||||||
<td><%=Html.Encode(row.Role.Name) %></td>
|
<td><%=Html.Encode(row.Name) %></td>
|
||||||
<td><%=Html.ActionLink("Edit", "Edit", new { row.Role.Id })%></td>
|
<td><%=Html.ActionLink("Edit", "Edit", new { row.Id })%></td>
|
||||||
</tr>
|
</tr>
|
||||||
<%}%>
|
<%}%>
|
||||||
</table>
|
</table>
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
using System;
|
using Autofac.Builder;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Autofac;
|
|
||||||
using Autofac.Builder;
|
|
||||||
|
|
||||||
namespace Orchard.Data {
|
namespace Orchard.Data {
|
||||||
public class DataModule : Module {
|
public class DataModule : Module {
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using FluentNHibernate.Automapping;
|
using FluentNHibernate.Automapping;
|
||||||
@ -29,6 +26,7 @@ namespace Orchard.Data {
|
|||||||
var automaps = new[] {
|
var automaps = new[] {
|
||||||
CreatePersistenceModel(Assembly.Load("Orchard.CmsPages")),
|
CreatePersistenceModel(Assembly.Load("Orchard.CmsPages")),
|
||||||
CreatePersistenceModel(Assembly.Load("Orchard.Users")),
|
CreatePersistenceModel(Assembly.Load("Orchard.Users")),
|
||||||
|
CreatePersistenceModel(Assembly.Load("Orchard.Roles")),
|
||||||
CreatePersistenceModel(Assembly.Load("Orchard")),
|
CreatePersistenceModel(Assembly.Load("Orchard")),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user