2009-11-12 03:46:14 +00:00
|
|
|
using System;
|
2009-11-10 17:33:39 +00:00
|
|
|
using System.Linq;
|
2009-11-10 03:41:01 +00:00
|
|
|
using System.Web.Mvc;
|
2009-11-10 17:33:39 +00:00
|
|
|
using Orchard.Data;
|
|
|
|
using Orchard.Models;
|
2009-11-12 03:46:14 +00:00
|
|
|
using Orchard.Security;
|
2009-11-12 19:19:45 +00:00
|
|
|
using Orchard.UI.Notify;
|
2009-11-10 17:33:39 +00:00
|
|
|
using Orchard.Users.Models;
|
|
|
|
using Orchard.Users.ViewModels;
|
2009-11-10 03:41:01 +00:00
|
|
|
|
|
|
|
namespace Orchard.Users.Controllers {
|
2009-11-12 19:56:13 +00:00
|
|
|
public class AdminController : Controller {
|
2009-11-10 17:33:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-12 19:56:13 +00:00
|
|
|
public IUser CurrentUser { get; set; }
|
|
|
|
|
2009-11-10 03:41:01 +00:00
|
|
|
public ActionResult Index() {
|
2009-11-10 17:33:39 +00:00
|
|
|
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);
|
2009-11-10 03:41:01 +00:00
|
|
|
}
|
|
|
|
|
2009-11-10 17:33:39 +00:00
|
|
|
[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) };
|
|
|
|
return View(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Edit(int id, FormCollection input) {
|
|
|
|
var model = new UserEditViewModel { User = _modelManager.Get(id) };
|
|
|
|
if (!TryUpdateModel(model, input.ToValueProvider())) {
|
|
|
|
return View(model);
|
|
|
|
}
|
|
|
|
_notifier.Information("User information updated");
|
|
|
|
return RedirectToAction("Edit", new { id });
|
|
|
|
}
|
2009-11-12 03:46:14 +00:00
|
|
|
|
2009-11-10 03:41:01 +00:00
|
|
|
}
|
2009-11-10 17:33:39 +00:00
|
|
|
|
2009-11-10 03:41:01 +00:00
|
|
|
}
|