Basic implementation - largely untested

This commit is contained in:
2014-01-20 22:40:40 -05:00
parent 6fbde2bc13
commit 1feda1b520
5 changed files with 194 additions and 0 deletions
+35
View File
@@ -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)