Cleanup and fixes

This commit is contained in:
2013-01-12 14:58:33 -05:00
parent bc019923d2
commit e50052d41e
27 changed files with 240 additions and 156 deletions
+38 -10
View File
@@ -2,9 +2,10 @@
using System.Linq;
using System.Web.Mvc;
using System.Web.Security;
using MileageTraker.Web.Attributes;
using MileageTraker.Web.Email;
using MileageTraker.Web.Utility;
using MileageTraker.Web.ViewModels;
using MileageTraker.Web.ViewModels.Account;
using MileageTraker.Web.ViewModels.User;
namespace MileageTraker.Web.Controllers
@@ -18,13 +19,28 @@ namespace MileageTraker.Web.Controllers
DataService
.GetUsers()
.ToList()
//.Where(u => u.Filter(q))
.OrderBy(u => u.Username);
return View(users);
}
//todo: add export
[ActionLog]
public ActionResult Export()
{
var users = DataService.GetUsers();
var userViewModels =
users
.ToList()
.OrderBy(u => u.Username)
.Select(log => new ExportUserViewModel(log));
var name = string.Format(
"MileageTrakerUsers_{0:MM-dd-yyyy}", DateTime.Today);
var export = ExcelWriter.WriteXls(userViewModels, name, name);
return File(export, "application/ms-excel", name + ".xls");
}
public ActionResult Details(Guid id)
{
@@ -78,6 +94,7 @@ namespace MileageTraker.Web.Controllers
return View(vm);
}
[ActionLog]
[HttpPost]
public ActionResult Create(CreateUserViewModel viewModel)
{
@@ -101,7 +118,7 @@ namespace MileageTraker.Web.Controllers
return View(viewModel);
}
if (viewModel.Roles.Selected != null && viewModel.Roles.Selected.Any())
if (viewModel.Roles != null)
{
Roles.AddUserToRoles(
membershipUser.UserName,
@@ -150,14 +167,15 @@ namespace MileageTraker.Web.Controllers
return View(vm);
}
[ActionLog]
[HttpPost]
public ActionResult Edit(EditUserViewModel viewModel)
{
if (ModelState.IsValid)
{
{
if (ModelState.IsValid)
{
var user = DataService.GetUser(viewModel.UserId);
viewModel.UpdateUser(user);
DataService.UpdateUserPersonalInfo(user);
DataService.UpdateUserPersonalInfo(user);
Roles.RemoveUserFromRoles(user.Username, Roles.GetAllRoles());
if (viewModel.Roles != null)
@@ -169,9 +187,9 @@ namespace MileageTraker.Web.Controllers
TempData["StatusMessage"] = "Changes saved for " + user.Username;
return RedirectToAction("Details", new { id = viewModel.UserId});
}
}
return View(viewModel);
}
}
public ActionResult SetPassword(Guid id)
{
@@ -197,6 +215,7 @@ namespace MileageTraker.Web.Controllers
return View(viewModel);
}
[ActionLog]
public ActionResult DisableUser(Guid id)
{
var user = DataService.GetUser(id);
@@ -214,6 +233,7 @@ namespace MileageTraker.Web.Controllers
return RedirectToAction("Index");
}
[ActionLog]
public ActionResult EnableUser(Guid id)
{
var user = DataService.GetUser(id);
@@ -231,6 +251,7 @@ namespace MileageTraker.Web.Controllers
return RedirectToAction("Index");
}
[ActionLog]
public ActionResult UnlockUser(Guid id)
{
var user = DataService.GetUser(id);
@@ -249,6 +270,13 @@ namespace MileageTraker.Web.Controllers
return RedirectToAction("Index");
}
[Authorize(Roles = "Driver, Administrator, Developer")]
public JsonResult Autocomplete(string term)
{
var employees = DataService.GetUserFullNamesAutocomplete(term);
return Json(employees, JsonRequestBehavior.AllowGet);
}
private static string ErrorCodeToString(MembershipCreateStatus createStatus)
{
// See http://go.microsoft.com/fwlink/?LinkID=177550 for