vgquotes/Src/VideoGameQuotes.Web/Controllers/AdminController.cs
tmont b45c82e5fa * quote editing, although not quite finished
* flag dismissal
* fixed some mapping issues by adding inverse="true" to some one-to-many relationships
2011-02-19 09:41:09 +00:00

57 lines
1.4 KiB
C#

using System.Web.Mvc;
using Portoa.Web;
using Portoa.Web.ErrorHandling;
using VideoGameQuotes.Api;
using VideoGameQuotes.Web.Models;
using VideoGameQuotes.Web.Security;
using VideoGameQuotes.Web.Services;
namespace VideoGameQuotes.Web.Controllers {
[IsValidUser(Group = UserGroup.Admin)]
public class AdminController : Controller {
private readonly ICurrentUserProvider userProvider;
private readonly IAdministrationService adminService;
public AdminController(ICurrentUserProvider userProvider, IAdministrationService adminService) {
this.userProvider = userProvider;
this.adminService = adminService;
}
public ActionResult Index() {
return View();
}
[HttpGet]
public ActionResult Password() {
return View(new ChangePasswordModel());
}
[HttpPost]
public ActionResult Password(ChangePasswordModel model) {
if (!ModelState.IsValid) {
return View(model);
}
var user = userProvider.CurrentUser;
if (user == null) {
return View("Unknown", new ErrorModel());
}
try {
user.ChangePassword(model.Password);
adminService.SaveUser(user);
return View("PasswordSuccessfullyChanged");
} catch {
ControllerContext.AddModelError("password", "Unable to change password");
return View(model);
}
}
[HttpGet]
public ActionResult Flags() {
var flaggedQuotes = adminService.GetFlaggedQuotes();
return View(flaggedQuotes);
}
}
}