private void btSave_Click(object sender, EventArgs e)
        {
            //Recipe recipe = new Recipe();
            double   minutes  = double.Parse(tbDuration.Text);
            Category category = (Category)cbCategory.SelectedItem;

            recipe.Title        = tbName.Text;
            recipe.CategoryID   = category.ID;
            recipe.Difficulty   = (Difficulty)cbDifficulty.SelectedItem;
            recipe.Duration     = TimeSpan.FromMinutes(minutes);
            recipe.Instructions = tbInstructions.Text;

            _rService.Add(recipe);

            int id = recipe.ID;

            foreach (DataRow row in dtInsertIngredients.Rows)
            {
                RecipeIngredient recipeIngredient = new RecipeIngredient();
                recipeIngredient.RecipeID     = id;
                recipeIngredient.IngredientID = Convert.ToInt32(row["ID"].ToString());
                recipeIngredient.Quantity     = Convert.ToDecimal(row["Quantidade"].ToString());
                recipeIngredient.Unit         = row["Unidade"].ToString();
                _riService.Add(recipeIngredient);
            }
            MessageBox.Show("Inserido com sucesso", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #2
0
        protected void btnInsertRecibe_Click(object sender, EventArgs e)
        {
            double minutes = double.Parse(tbDuration.Text);

            _membershipUsername = User.Identity.Name;
            foreach (User user in _uService.GetALL())
            {
                if (_membershipUsername == user.MembershipUsername)
                {
                    userId = user.ID;
                }
            }

            recipe.Title        = tbName.Text;
            recipe.CategoryID   = int.Parse(cbCategory.SelectedValue);
            recipe.Difficulty   = (Difficulty)cbDifficulty.SelectedIndex;
            recipe.Duration     = TimeSpan.FromMinutes(minutes);
            recipe.Instructions = tbInstructions.Text;
            recipe.User         = userId;

            _rService.Add(recipe);

            int id = recipe.ID;

            dt = (DataTable)ViewState["Records"];
            foreach (DataRow row in dt.Rows)
            {
                RecipeIngredient recipeIngredient = new RecipeIngredient();
                recipeIngredient.RecipeID     = id;
                recipeIngredient.IngredientID = Convert.ToInt32(row["ID"].ToString());
                recipeIngredient.Quantity     = Convert.ToDecimal(row["Quantidade"].ToString());
                recipeIngredient.Unit         = row["Unidade"].ToString();
                _riService.Add(recipeIngredient);
            }
            Response.Redirect("~/asminhasreceitas.aspx");
        }