mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 13:33:34 +08:00

--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4040309
87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using Orchard.Data;
|
|
using Orchard.Localization;
|
|
using Orchard.Models;
|
|
using Orchard.Models.Driver;
|
|
using Orchard.Security;
|
|
using Orchard.UI.Notify;
|
|
using Orchard.Users.Models;
|
|
using Orchard.Users.ViewModels;
|
|
|
|
namespace Orchard.Users.Controllers {
|
|
|
|
public class AdminController : Controller, IModelUpdater {
|
|
private readonly IModelManager _modelManager;
|
|
private readonly IRepository<UserRecord> _userRepository;
|
|
private readonly INotifier _notifier;
|
|
|
|
public AdminController(
|
|
IModelManager modelManager,
|
|
IRepository<UserRecord> userRepository,
|
|
INotifier notifier) {
|
|
_modelManager = modelManager;
|
|
_userRepository = userRepository;
|
|
_notifier = notifier;
|
|
T = NullLocalizer.Instance;
|
|
}
|
|
|
|
public IUser CurrentUser { get; set; }
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
public ActionResult Index() {
|
|
var model = new UsersIndexViewModel();
|
|
model.Rows = _userRepository.Fetch(x => x.UserName != null)
|
|
.Select(x => new UsersIndexViewModel.Row {
|
|
User = _modelManager.Get(x.Id).As<UserModel>()
|
|
})
|
|
.ToList();
|
|
|
|
return View(model);
|
|
}
|
|
|
|
public ActionResult Create() {
|
|
var model = new UserCreateViewModel();
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Create(UserCreateViewModel model) {
|
|
if (ModelState.IsValid == false) {
|
|
return View(model);
|
|
}
|
|
var user = _modelManager.New("user");
|
|
user.As<UserModel>().Record = new UserRecord { UserName = model.UserName, Email = model.Email };
|
|
_modelManager.Create(user);
|
|
return RedirectToAction("edit", new { user.Id });
|
|
}
|
|
|
|
public ActionResult Edit(int id) {
|
|
var model = new UserEditViewModel { User = _modelManager.Get(id) };
|
|
model.Editors = _modelManager.GetEditors(model.User);
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Edit(int id, FormCollection input) {
|
|
var model = new UserEditViewModel { User = _modelManager.Get(id) };
|
|
model.Editors = _modelManager.UpdateEditors(model.User, this);
|
|
|
|
if (!TryUpdateModel(model, input.ToValueProvider())) {
|
|
return View(model);
|
|
}
|
|
|
|
_notifier.Information(T("User information updated"));
|
|
return RedirectToAction("Edit", new { id });
|
|
}
|
|
|
|
|
|
bool IModelUpdater.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
|
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
|
}
|
|
}
|
|
|
|
}
|