Add ability to fix errors during import

This commit is contained in:
2014-02-03 21:16:35 -05:00
parent 3ab80e283a
commit 8b8d82f3d3
8 changed files with 88 additions and 49 deletions
+24 -39
View File
@@ -7,10 +7,8 @@ using System.Web.Mvc;
using System.Web.Routing;
using MileageTraker.Web.Attributes;
using MileageTraker.Web.DAL;
using MileageTraker.Web.Models;
using MileageTraker.Web.Utility;
using MileageTraker.Web.ViewModels;
using MileageTraker.Web.ViewModels.CreateLog;
using MileageTraker.Web.ViewModels.Log;
using MileageTraker.Web.ViewModels.Vehicle;
@@ -174,13 +172,6 @@ namespace MileageTraker.Web.Controllers
return View(viewModel);
}
[HttpGet]
public ActionResult Create(LogImportViewModel viewModel)
{
// TODO: complete?
return View();
}
public ActionResult Edit(int id)
{
var log = DataService.GetLog(id);
@@ -250,7 +241,6 @@ namespace MileageTraker.Web.Controllers
return PartialView(new LogPartialDetails(log));
}
// TODO: Fix?
public ActionResult ImportUpload()
{
return View();
@@ -306,24 +296,8 @@ namespace MileageTraker.Web.Controllers
{
var buttonAttributes = new Dictionary<string, object> { { "class", "btn btn-mini" }, { "target", "_blank" } };
var correctItLink = HtmlHelper.GenerateLink(
ControllerContext.RequestContext, RouteTable.Routes,
"Correct", "Default", "Create", "Log",
null,
buttonAttributes);
try
{
// verify log type
if (!typeof (MileageLogType).IsValidValue(viewModel.LogType))
{
return Json(new
{
Status = ImportStatus.Failure.ToString(),
Message = "Invalid Log Type: \"" + viewModel.LogType + "\"",
//Action = correctItLink
}, JsonRequestBehavior.AllowGet);
}
// verify purpose
var purposeType = DataService.FindPurposeType(viewModel.Purpose);
if (purposeType == null)
@@ -332,7 +306,7 @@ namespace MileageTraker.Web.Controllers
{
Status = ImportStatus.Failure.ToString(),
Message = "Invalid Purpose: " + viewModel.Purpose,
//Action = correctItLink
Action = GetFixLink(viewModel)
}, JsonRequestBehavior.AllowGet);
}
@@ -346,7 +320,7 @@ namespace MileageTraker.Web.Controllers
{
Status = ImportStatus.Failure.ToString(),
Message = string.Join(", ", errorList),
//Action = correctItLink
Action = GetFixLink(viewModel)
}, JsonRequestBehavior.AllowGet);
}
@@ -380,7 +354,7 @@ namespace MileageTraker.Web.Controllers
{
Status = ImportStatus.Failure.ToString(),
Message = "Vehile with supplied ID does not exist",
Action = correctItLink
Action = GetFixLink(viewModel)
}, JsonRequestBehavior.AllowGet);
}
@@ -413,7 +387,7 @@ namespace MileageTraker.Web.Controllers
{
Status = ImportStatus.Failure.ToString(),
Message = fullErrorMessage,
Action = correctItLink
Action = GetFixLink(viewModel)
},
JsonRequestBehavior.AllowGet);
}
@@ -424,20 +398,31 @@ namespace MileageTraker.Web.Controllers
{
Status = ImportStatus.Failure.ToString(),
Message = message,
Action = correctItLink
Action = GetFixLink(viewModel)
}, JsonRequestBehavior.AllowGet);
}
}
private static IEnumerable<string> GetModelStateErrorList(ModelStateDictionary modelStateDictionary)
private string GetFixLink(LogImportViewModel viewModel)
{
var errorList =
from kvp in modelStateDictionary
where kvp.Value.Errors.Any()
let errors = string.Join(", ", kvp.Value.Errors.Select(e => e.ErrorMessage))
let msg = kvp.Key + ": " + errors
select msg;
return errorList;
try
{
viewModel.GetLogViewModel();
}
catch
{
return string.Empty;
}
return RenderRazorViewToString("LogImportPartial", viewModel);
}
[HttpPost]
public ActionResult ImportFix(LogImportViewModel viewModel)
{
var logViewModel = viewModel.GetLogViewModel();
logViewModel.Purpose.Available = GetPurposeTypesSelectList();
return View("Create", logViewModel);
}
public ActionResult ImportTemplate()