/// <summary> /// Adds an amount to the database. /// </summary> /// <param name="amount">A amount-object</param> /*public void AmountFormView_InsertItem(Amount amount) { if (Page.ModelState.IsValid) { try { amount.RecipeID = RecipeID; Service.SaveAmount(amount); } catch (Exception) { ModelState.AddModelError(String.Empty, Amount_Insert_Error); } } }*/ /// <summary> /// Adds an recipe and amount to the database. /// </summary> /// <param name="recipe">A recipe-object</param> /// <param name="amount">A amount-object</param> public void RecipeFormView_InsertItem(Recipe recipe, Amount amount) { if (Page.ModelState.IsValid) { try { Service.SaveRecipe(recipe, amount); Message = Action_Recipe_Added; Response.RedirectToRoute("RecipeDetails", new { id = recipe.RecipeID }); Context.ApplicationInstance.CompleteRequest(); } catch (Exception) { ModelState.AddModelError(String.Empty, Recipe_Insert_Error); } } }
/// <summary> /// Save the recipe information to the database. /// </summary> /// <param name="recipe">Recipe information that will be saved.</param> public void SaveRecipe(Recipe recipe, Amount amount) { ICollection<ValidationResult> validationResults; if (!recipe.Validate(out validationResults)) { var ex = new ValidationException(Validation_Object_Error); ex.Data.Add("ValidationResult", validationResults); throw ex; } // Create a new entry if RecipeID is equal to zero. if (recipe.RecipeID == 0) { RecipeDAL.InsertRecipe(recipe, amount); } else { RecipeDAL.UpdateRecipe(recipe); } }