public ActionResult Create(FeatureCreateEditViewModel viewModel) { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { var feature = new Feature(); viewModel.ApplyToEntity(context, feature); context.Features.Add(feature); if (context.SaveChanges(CreateValidationFailed)) { Flash.Success(String.Format("Feature {0} was created.", feature.FeatureName)); return RedirectToAction("Index"); } } } //Viewmodel invalid, recall create return Create(); }
public ActionResult Edit(FeatureCreateEditViewModel viewModel) { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { Model.Feature feature = (from f in context.Features where f.FeatureId == viewModel.Feature.FeatureId select f).SingleOrDefault(); if (feature == null) return new HttpStatusCodeResult(HttpStatusCode.NotFound); viewModel.ApplyToEntity(context, feature); if (context.SaveChanges(CreateValidationFailed)) { Flash.Success("The feature was updated."); return RedirectToAction("Index"); } } } return Edit(viewModel.Feature.FeatureId); }