Combine layouts
This commit is contained in:
@@ -2,13 +2,12 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using MileageTraker.Web.Membership;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.Account;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class AccountController : Controller
|
||||
public class AccountController : ControllerBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
public ActionResult Login(string returnUrl)
|
||||
@@ -40,7 +39,7 @@ namespace MileageTraker.Web.Controllers
|
||||
WebSecurity.Logout();
|
||||
|
||||
// TODO: send notification to user
|
||||
return RedirectToAction("Login");
|
||||
return RedirectToAction("Index", "CreateLog");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.DAL;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
public class CityController : ControllerBase
|
||||
{
|
||||
private readonly DataService _dataService = new DataService();
|
||||
|
||||
public JsonResult Autocomplete(string term)
|
||||
{
|
||||
var cities = _dataService.GetCitiesAutocomplete(term);
|
||||
var cities = DataService.GetCitiesAutocomplete(term);
|
||||
return Json(cities, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.DAL;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
public class ControllerBase : Controller
|
||||
{
|
||||
protected readonly DataService DataService = new DataService();
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
DataService.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override void OnException(ExceptionContext filterContext)
|
||||
{
|
||||
if (filterContext != null && filterContext.Exception != null)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.CreateLog;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
@@ -13,7 +12,6 @@ namespace MileageTraker.Web.Controllers
|
||||
private const string CookieKeyEmployeename = "mr_employeeName";
|
||||
private const string CookeNameVehicleid = "mr_vehicleId";
|
||||
private const string CookieKeyLogtype = "mr_logType";
|
||||
private readonly DataService _dataService = new DataService();
|
||||
|
||||
public ViewResult Index()
|
||||
{
|
||||
@@ -61,7 +59,7 @@ namespace MileageTraker.Web.Controllers
|
||||
log.Source = HttpContext.Request.Url.AbsolutePath;
|
||||
log.UserHostAddress = HttpContext.Request.UserHostAddress;
|
||||
log.UserAgent = HttpContext.Request.UserAgent;
|
||||
_dataService.AddLog(log);
|
||||
DataService.AddLog(log);
|
||||
return View("Success", model);
|
||||
}
|
||||
|
||||
@@ -70,7 +68,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public PartialViewResult RecentLogs(string employeeName)
|
||||
{
|
||||
var logs = _dataService.GetRecentLogsByEmployee(employeeName);
|
||||
var logs = DataService.GetRecentLogsByEmployee(employeeName);
|
||||
ViewData["employeeName"] = employeeName;
|
||||
return PartialView(logs);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.DAL;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
public class EmployeeController : Controller
|
||||
public class EmployeeController : ControllerBase
|
||||
{
|
||||
private readonly DataService _dataService = new DataService();
|
||||
|
||||
public JsonResult Autocomplete(string term)
|
||||
{
|
||||
var employees = _dataService.GetEmployeeNamesAutocomplete(term);
|
||||
var employees = DataService.GetEmployeeNamesAutocomplete(term);
|
||||
return Json(employees, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
@@ -13,24 +14,22 @@ namespace MileageTraker.Web.Controllers
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public class LogController : ControllerBase
|
||||
{
|
||||
private readonly DataService _dataService = new DataService();
|
||||
|
||||
public ViewResult Index(LogQueryViewModel query)
|
||||
{
|
||||
var logs = _dataService.GetLogs();
|
||||
var logs = DataService.GetLogs();
|
||||
|
||||
var validLogYears = _dataService.GetValidLogYears().ToList();
|
||||
var validLogYears = DataService.GetValidLogYears().ToList();
|
||||
if (!validLogYears.Any())
|
||||
return View("Empty");
|
||||
if (!query.Year.HasValue)
|
||||
query.Year = validLogYears.FirstOrDefault();
|
||||
|
||||
var validLogMonths = _dataService.GetValidLogMonths(query.Year.Value).ToList();
|
||||
var validLogMonths = DataService.GetValidLogMonths(query.Year.Value).ToList();
|
||||
if (!query.Month.HasValue)
|
||||
query.Month = validLogMonths.FirstOrDefault();
|
||||
|
||||
var filteredLogs =
|
||||
from log in _dataService.GetLogIndexViewModels(DataService.FilterLogs(logs, query))
|
||||
from log in DataService.GetLogIndexViewModels(DataService.FilterLogs(logs, query))
|
||||
orderby log.Created descending
|
||||
select log;
|
||||
|
||||
@@ -53,7 +52,7 @@ namespace MileageTraker.Web.Controllers
|
||||
[ActionLog]
|
||||
public ActionResult Export(LogQueryViewModel query)
|
||||
{
|
||||
var logs = _dataService.GetLogs();
|
||||
var logs = DataService.GetLogs();
|
||||
var name = string.Format(
|
||||
"MileageLogs{0}-{1}{2}",
|
||||
query.Year,
|
||||
@@ -66,7 +65,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ViewResult MonthlyVehicleMileage(LogQueryViewModel query)
|
||||
{
|
||||
var items = _dataService.GetMonthlyVehicleMileageItems(query);
|
||||
var items = DataService.GetMonthlyVehicleMileageItems(query);
|
||||
|
||||
var report = new VehicleMileageViewModel (items, query);
|
||||
|
||||
@@ -75,7 +74,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ActionResult MonthlyEmployeeMileage(LogQueryViewModel query)
|
||||
{
|
||||
var items = _dataService.GetMonthlyEmployeeMileageItems(query);
|
||||
var items = DataService.GetMonthlyEmployeeMileageItems(query);
|
||||
|
||||
var report = new EmployeeMileageViewModel(items, query);
|
||||
|
||||
@@ -84,13 +83,13 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ViewResult Details(int id)
|
||||
{
|
||||
var log = _dataService.GetLog(id);
|
||||
var log = DataService.GetLog(id);
|
||||
return View(log);
|
||||
}
|
||||
|
||||
public ActionResult PreviousDetails(int id)
|
||||
{
|
||||
var log = _dataService.GetLog(id);
|
||||
var log = DataService.GetLog(id);
|
||||
int logId;
|
||||
if (log.VehiclePreviousLog != null)
|
||||
{
|
||||
@@ -106,7 +105,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ActionResult NextDetails(int id)
|
||||
{
|
||||
var nextLog = _dataService.GetNextLog(id);
|
||||
var nextLog = DataService.GetNextLog(id);
|
||||
int logId;
|
||||
if (nextLog != null)
|
||||
{
|
||||
@@ -142,7 +141,7 @@ namespace MileageTraker.Web.Controllers
|
||||
log.UserHostAddress = HttpContext.Request.UserHostAddress;
|
||||
log.UserAgent = HttpContext.Request.UserAgent;
|
||||
|
||||
_dataService.AddLog(log);
|
||||
DataService.AddLog(log);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
@@ -151,7 +150,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
var log = _dataService.GetLog(id);
|
||||
var log = DataService.GetLog(id);
|
||||
return View(log);
|
||||
}
|
||||
|
||||
@@ -162,7 +161,7 @@ namespace MileageTraker.Web.Controllers
|
||||
RemoveModelStateErrors();
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_dataService.UpdateLog(log);
|
||||
DataService.UpdateLog(log);
|
||||
return RedirectToAction("Details", new{id = log.LogId});
|
||||
}
|
||||
return View(log);
|
||||
@@ -179,7 +178,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
var log = _dataService.GetLog(id);
|
||||
var log = DataService.GetLog(id);
|
||||
return View(log);
|
||||
}
|
||||
|
||||
@@ -187,7 +186,7 @@ namespace MileageTraker.Web.Controllers
|
||||
[ActionLog]
|
||||
public ActionResult DeleteConfirmed(int id)
|
||||
{
|
||||
_dataService.DeleteLog(id);
|
||||
DataService.DeleteLog(id);
|
||||
|
||||
if (Session["LogPage"] != null)
|
||||
return Redirect((string) Session["LogPage"]);
|
||||
@@ -196,20 +195,14 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public JsonResult GetValidLogMonths(int year)
|
||||
{
|
||||
var validLogMonths = _dataService.GetValidLogMonths(year);
|
||||
var validLogMonths = DataService.GetValidLogMonths(year);
|
||||
return Json(validLogMonths, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public PartialViewResult DetailsPartial(int id)
|
||||
{
|
||||
var log = _dataService.GetLog(id);
|
||||
var log = DataService.GetLog(id);
|
||||
return PartialView(new LogPartialDetails(log));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_dataService.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Context;
|
||||
using MileageTraker.Web.ViewModels.User;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View(DataService.GetUsers().ToList());
|
||||
}
|
||||
|
||||
public ActionResult Details(Guid id)
|
||||
{
|
||||
var user = DataService.GetUser(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
public ActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(CreateUserViewModel createUserViewModel)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var user = createUserViewModel.CloneToUser();
|
||||
user.UserId = Guid.NewGuid();
|
||||
//db.Users.Add(user);
|
||||
//db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return View(createUserViewModel);
|
||||
}
|
||||
|
||||
public ActionResult Edit(Guid id)
|
||||
{
|
||||
var user = DataService.GetUser(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(User user)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
//db.Entry(user).State = EntityState.Modified;
|
||||
//db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.Vehicle;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
@@ -10,23 +9,21 @@ namespace MileageTraker.Web.Controllers
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public class VehicleController : ControllerBase
|
||||
{
|
||||
private readonly DataService _ds = new DataService();
|
||||
|
||||
public ViewResult Index()
|
||||
{
|
||||
var vehicles = _ds.GetVehicles();
|
||||
var vehicles = DataService.GetVehicles();
|
||||
return View(vehicles);
|
||||
}
|
||||
|
||||
public ViewResult Details(string id)
|
||||
{
|
||||
var vehicle = _ds.GetVehicle(id);
|
||||
var vehicle = DataService.GetVehicle(id);
|
||||
return View(vehicle);
|
||||
}
|
||||
|
||||
public PartialViewResult DetailsPartial(string id)
|
||||
{
|
||||
var vehicle = _ds.GetVehicle(id);
|
||||
var vehicle = DataService.GetVehicle(id);
|
||||
return PartialView(new VehiclePartialDetails(vehicle));
|
||||
}
|
||||
|
||||
@@ -40,7 +37,7 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_ds.AddVehicle(vehicle);
|
||||
DataService.AddVehicle(vehicle);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
@@ -49,7 +46,7 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ActionResult Edit(string id)
|
||||
{
|
||||
var vehicle = _ds.GetVehicle(id);
|
||||
var vehicle = DataService.GetVehicle(id);
|
||||
return View(vehicle);
|
||||
}
|
||||
|
||||
@@ -58,7 +55,7 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_ds.UpdateVehicle(vehicle);
|
||||
DataService.UpdateVehicle(vehicle);
|
||||
return RedirectToAction("Details", new { id = vehicle.VehicleId });
|
||||
}
|
||||
return View(vehicle);
|
||||
@@ -66,21 +63,15 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public JsonResult Exists(string vehicleId)
|
||||
{
|
||||
var vehicle = _ds.GetVehicle(vehicleId);
|
||||
var vehicle = DataService.GetVehicle(vehicleId);
|
||||
return Json(vehicle != null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public FileResult Export()
|
||||
{
|
||||
var vehicles = _ds.GetVehicles();
|
||||
var vehicles = DataService.GetVehicles();
|
||||
var export = VehicleImporter.Export(vehicles);
|
||||
return File(export, "application/ms-excel", string.Format("ETHRAVehicles{0:yyyy-MM-dd}.xls", DateTime.Today));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_ds.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user