Methodize status message handling

This commit is contained in:
2015-10-10 22:42:38 -04:00
parent 6482955b3c
commit 22e4089fba
10 changed files with 71 additions and 66 deletions
+10 -14
View File
@@ -107,7 +107,7 @@ namespace MileageTraker.Web.Controllers
else
{
logId = id;
TempData["StatusMessage"] = "This is the first log for this vehicle";
SetStatusMessage("This is the first log for this vehicle");
}
return RedirectToAction("Details", new {id = logId});
}
@@ -123,7 +123,7 @@ namespace MileageTraker.Web.Controllers
else
{
logId = id;
TempData["StatusMessage"] = "This is the most recent log for this vehicle";
SetStatusMessage("This is the most recent log for this vehicle");
}
return RedirectToAction("Details", new { id = logId });
}
@@ -161,8 +161,7 @@ namespace MileageTraker.Web.Controllers
DataService.AddLog(log);
TempData["StatusMessage-Type"] = "alert-success";
TempData["StatusMessage"] = "Log created";
SetStatusMessage("Log created", StatusType.Success);
if (TempData.ContainsKey("FuelLogId"))
{
@@ -173,8 +172,7 @@ namespace MileageTraker.Web.Controllers
DataService.UpdateFuelLog(fuelLog);
// return to the fuel log match page
TempData["StatusMessage-Type"] = "alert-success";
TempData["StatusMessage"] = "Log created and matched to the fuel log";
SetStatusMessage("Log created and matched to the fuel log", StatusType.Success);
return RedirectToAction("Match", "FuelLog", new {id = fuelLogId});
}
@@ -213,7 +211,7 @@ namespace MileageTraker.Web.Controllers
DataService.UpdateLog(log);
TempData["StatusMessage"] = "Log updated";
SetStatusMessage("Log updated");
return RedirectToAction("Details", new{id = log.LogId});
}
@@ -237,7 +235,7 @@ namespace MileageTraker.Web.Controllers
{
DataService.DeleteLog(id);
TempData["StatusMessage"] = "Log deleted";
SetStatusMessage("Log deleted");
if (Session["LogPage"] != null)
return Redirect((string) Session["LogPage"]);
return RedirectToAction("Index");
@@ -265,8 +263,7 @@ namespace MileageTraker.Web.Controllers
DataService.FindUserByUsername(viewModel.UserName);
if (user == null)
{
TempData["StatusMessage"] = "User " + viewModel.UserName + " not found";
TempData["StatusMessage-Type"] = "alert-error";
SetStatusMessage("User " + viewModel.UserName + " not found", StatusType.Error);
}
else
{
@@ -284,13 +281,12 @@ namespace MileageTraker.Web.Controllers
}
catch (OutOfMemoryException)
{
TempData["StatusMessage"] = "Problem reading excel document - please verify that the document is in Excel 97-2003 Workbook (.xls) format";
TempData["StatusMessage-Type"] = "alert-error";
SetStatusMessage(
"Problem reading excel document - please verify that the document is in Excel 97-2003 Workbook (.xls) format", StatusType.Error);
}
catch (Exception ex)
{
TempData["StatusMessage"] = "Problem reading excel document: " + ex.Message;
TempData["StatusMessage-Type"] = "alert-error";
SetStatusMessage("Problem reading excel document: " + ex.Message, StatusType.Error);
}
}
}