public ActionResult EditUnit([Bind(Include = "Id,Title,ContentUrl")] EditUnitBindingModel model) { if (this.ModelState.IsValid) { this.service.EditUnit(model); return(this.RedirectToAction("UnitPreview", new { id = model.Id })); } EditUnitViewModel viewModel = this.service.GetEditUnitViewModel(model.Id); return(this.View(viewModel)); }
public void EditUnit(EditUnitBindingModel model) { Unit unit = this.Context.Units.Find(model.Id); if (unit == null) { throw new ArgumentNullException(nameof(model.Id), "There is no Unit with such Id."); } unit.Title = model.Title; unit.ContentUrl = model.ContentUrl; this.Context.SaveChanges(); }