public ActionResult Edit(RecipeEditViewModel recipe) { try { // Yes, it's a bit chatty, but we need to // validate the entity from the database. var recipeEntity = this._recipeRepository.GetRecipe(recipe.RecipeId); if (!CanEdit(recipeEntity)) { // Simply return the user to the detail view. // Not too worried about the throw. return RedirectToAction("Details", new { id = recipe.RecipeId }); } var entityToSave = this ._editViewModelMapper .ViewModelToEntity(recipe); this._recipeRepository.Save(entityToSave); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(RecipeEditViewModel recipe) { try { if (ModelState.IsValid) { var recipeEntity = this._editViewModelMapper.ViewModelToEntity(recipe); this._recipeRepository.Save(recipeEntity); var context = Microsoft.AspNet.SignalR. GlobalHost .ConnectionManager .GetHubContext<RecipeHub>(); context .Clients .All .recipeAdded( _displayViewModelMapper .EntityToViewModel(recipeEntity) ); return RedirectToAction("Index"); } } catch { } return View(recipe); }