/// <summary> /// Adds an amount to the database. /// <param name="amount">The recipes amounts amount-object.</param> /// </summary> public void AmountListView_InsertItem(Amount amount) { if (Page.ModelState.IsValid) { try { amount.RecipeID = RecipeID; Service.SaveAmount(amount); Message = Action_Amount_Added; Response.RedirectToRoute("RecipeEdit", new { id = RecipeID }); Context.ApplicationInstance.CompleteRequest(); } catch (Exception) { ModelState.AddModelError(String.Empty, Amount_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); } }
/// <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 amount to the database. /// </summary> /// <param name="amount">The amount that will be saved.</param> public void SaveAmount(Amount amount) { ICollection<ValidationResult> validationResults; if (!amount.Validate(out validationResults)) { var ex = new ValidationException(Validation_Object_Error); ex.Data.Add("ValidationResult", validationResults); throw ex; } if (amount.AmountID == 0) { AmountDAL.InsertAmount(amount); } else { AmountDAL.UpdateAmount(amount); } }