public void AddDish(DishModel model)
 {
     var newDishId = dishProvider.AddDish(model);
     foreach (var ingredient in model.Ingredients)
     {
         ingredient.DishId = newDishId;
         ingredientProvider.AddIngredient(ingredient);
     }
 }
Ejemplo n.º 2
0
        private void addRecipeButton_Click(object sender, EventArgs e)
        {
            string newDishName = newRecipeNameTextField.Text;

            if (newDishName == string.Empty)
            {
                MessageBox.Show(Resources.DontLeaveNameFieldMessage, Resources.WarningMessage);
                return;
            }

            newDishModel.Name                = newDishName;
            newDishModel.OwnerId             = loggedUser.Id;
            newDishModel.CookingInstructions = this.newRecipeDescriptionRichTextField.Text;

            int newDishId = 0;

            try
            {
                newDishId = dishProvider.AddDish(newDishModel);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.ErrorMessage);
                return;
            }

            try
            {
                foreach (var ingredient in newRecipeIngredients)
                {
                    ingredient.DishId = newDishId;
                    ingredientProvider.AddIngredient(ingredient);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.ErrorMessage);
                return;
            }

            clearAddRecipePage();
            dishGridOptions.PageNumber = 1;
            this.pages.SelectedTab     = dishesPage;
        }
Ejemplo n.º 3
0
        public IActionResult AddDish(DishModel model)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                var newDishId = dishProvider.AddDish(model);

                foreach (var ingredient in model.Ingredients)
                {
                    ingredient.DishId = newDishId;
                    ingredientProvider.AddIngredient(ingredient);
                }

                // The Complete method commits the transaction. If an exception has been thrown,
                // Complete is not  called and the transaction is rolled back.
                scope.Complete();
            }

            return(Ok());
        }