public ActionResult Edit(PersonEditorViewModel item) { if (_Validator.IsValid(item) == true) { Person toValue; if (item.Id == ApiConstants.UnsavedId) { toValue = new Person(); } else { toValue = _Service.GetById(item.Id); if (toValue == null) { return(NotFound()); } } var adapter = new PersonEditorViewModelAdapter(); adapter.Adapt(item, toValue); _Service.Save(toValue); return(RedirectToAction("Edit", new { id = toValue.Id })); } else { return(View(item)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new BadRequestResult()); } Person item; PersonEditorViewModel viewModel; if (id.Value == ApiConstants.UnsavedId) { // create new viewModel = new PersonEditorViewModel(); PopulateLookups(viewModel); return(View(viewModel)); } else { item = _Service.GetById(id.Value); if (item == null) { return(NotFound()); } else { viewModel = new PersonEditorViewModel(); var adapter = new PersonEditorViewModelAdapter(); adapter.Adapt(item, viewModel); PopulateLookups(viewModel); } } return(View(viewModel)); }