Nearing feature complete for driver auth

This commit is contained in:
2013-01-09 21:33:57 -05:00
parent 0b4c7914b3
commit bc019923d2
49 changed files with 609 additions and 335 deletions
+21 -22
View File
@@ -3,7 +3,6 @@ using System.Linq;
using System.Web.Mvc;
using MileageTraker.Web.Attributes;
using MileageTraker.Web.DAL;
using MileageTraker.Web.Models;
using MileageTraker.Web.Utility;
using MileageTraker.Web.ViewModels;
using MileageTraker.Web.ViewModels.Log;
@@ -84,7 +83,8 @@ namespace MileageTraker.Web.Controllers
public ViewResult Details(int id)
{
var log = DataService.GetLog(id);
return View(log);
var viewModel = new LogViewModel(log);
return View(viewModel);
}
public ActionResult PreviousDetails(int id)
@@ -121,22 +121,24 @@ namespace MileageTraker.Web.Controllers
public ActionResult Create()
{
var log = new Log { Date = DateTime.Today };
var viewModel = new LogViewModel { Date = DateTime.Today };
var vehicleId = Request["vehicleId"];
if (vehicleId != null)
{
log.VehicleId = vehicleId;
viewModel.VehicleId = vehicleId;
}
return View(log);
return View(viewModel);
}
[HttpPost]
[ActionLog]
public ActionResult Create(Log log)
public ActionResult Create(LogViewModel viewModel)
{
if (ModelState.IsValid)
{
var log = viewModel.GetLog();
log.User = DataService.FindUserByFullName(viewModel.UserFullName);
log.Source = HttpContext.Request.Url.AbsolutePath;
log.UserHostAddress = HttpContext.Request.UserHostAddress;
log.UserAgent = HttpContext.Request.UserAgent;
@@ -147,42 +149,39 @@ namespace MileageTraker.Web.Controllers
return RedirectToAction("Index");
}
return View(log);
return View(viewModel);
}
public ActionResult Edit(int id)
{
var log = DataService.GetLog(id);
return View(log);
var logViewModel = new LogViewModel(log);
return View(logViewModel);
}
[HttpPost]
[ActionLog]
public ActionResult Edit(Log log)
public ActionResult Edit(LogViewModel viewModel)
{
RemoveModelStateErrors();
if (ModelState.IsValid)
{
DataService.UpdateLog(log);
var log = DataService.GetLog(viewModel.LogId);
viewModel.UpdateLog(log);
log.User = DataService.FindUserByFullName(viewModel.UserFullName);
DataService.UpdateLog(log);
TempData["StatusMessage"] = "Log updated";
return RedirectToAction("Details", new{id = log.LogId});
}
return View(log);
return View(viewModel);
}
private void RemoveModelStateErrors()
{
ModelState.Remove("Source");
ModelState.Remove("UserAgent");
ModelState.Remove("UserHostAddress");
ModelState.Remove("VehiclePreviousLogId");
ModelState.Remove("VehiclePreviousLog");
}
public ActionResult Delete(int id)
{
var log = DataService.GetLog(id);
return View(log);
var viewModel = new LogViewModel(log);
return View(viewModel);
}
[HttpPost, ActionName("Delete")]