Basic implementation - largely untested
This commit is contained in:
@@ -5,6 +5,7 @@ using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.ViewModels;
|
||||
using MileageTraker.Web.ViewModels.CreateLog;
|
||||
using MileageTraker.Web.ViewModels.Log;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
@@ -35,6 +36,40 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult EditPast(int id)
|
||||
{
|
||||
var log = DataService.GetLog(id);
|
||||
var viewModel = new EditPastViewModel(log)
|
||||
{
|
||||
Purpose = { Available = GetPurposeTypesSelectList() }
|
||||
};
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionLog]
|
||||
public ActionResult EditPast(EditPastViewModel viewModel)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var log = DataService.GetLog(viewModel.LogId);
|
||||
viewModel.SetProperties(log);
|
||||
|
||||
if (viewModel.Purpose != null)
|
||||
log.Purpose =
|
||||
DataService.GetPurposeTypes()
|
||||
.First(pt => pt.PurposeTypeId == viewModel.Purpose.Selected);
|
||||
|
||||
DataService.UpdateLog(log);
|
||||
|
||||
TempData["StatusMessage"] = "Log updated";
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
viewModel.Purpose.Available = GetPurposeTypesSelectList();
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpParamAction]
|
||||
[HttpPost]
|
||||
public ViewResult Edit(CreateLogViewModel model)
|
||||
|
||||
Reference in New Issue
Block a user