Exemplo n.º 1
0
        protected void btnAddNote_Click(object sender, EventArgs e)
        {
            if (tbNoteValue.Text != "" && tbName.Text != "")
            {
                RecipeCatalogEntities db = new RecipeCatalogEntities();
                Label lblRecipeId = (Label)fvSelectedRecipe.FindControl("lblRecipeId");
                int recpieId = int.Parse(lblRecipeId.Text);
                db.Notes.Add(new Note
                {
                    NoteValue = tbNoteValue.Text,
                    NoteWriter = tbName.Text,
                    RecipeRecipeId = recpieId

                });
                db.SaveChanges();
                tbName.Text = "";
                tbNoteValue.Text = "";

                var selectItem = int.Parse(lvRecipes.SelectedValue.ToString());
                var RecipeNotes = db.Notes.Where(n => n.Recipe.RecipeId == selectItem ).ToArray();
                lvSelectedRecipeNotes.DataSourceID = null;
                lvSelectedRecipeNotes.DataSource = RecipeNotes;
                lvSelectedRecipeNotes.DataBind();

            }
        }
Exemplo n.º 2
0
        protected void lvRecipes_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {
            this.lvRecipes.SelectedIndex = e.NewSelectedIndex;
            lvRecipes.DataSourceID = null;
            lvRecipes.DataSource = dsSearch;
            lvRecipes.DataBind();

            RecipeCatalogEntities db = new RecipeCatalogEntities();
            var selectItem = int.Parse(lvRecipes.SelectedValue.ToString());
            var RecipeNotes = db.Notes.Where(n => n.Recipe.RecipeId == selectItem ).ToArray();
            lvSelectedRecipeNotes.DataSourceID = null;
            lvSelectedRecipeNotes.DataSource = RecipeNotes;
            lvSelectedRecipeNotes.DataBind();

            mvRecipes.ActiveViewIndex = 1;
        }
        protected void Add_Recipe(object sender, EventArgs e)
        {
            RecipeCatalogEntities db = new RecipeCatalogEntities();
            //string ingredientList = "";
            //foreach (var item in lbIngredients.Items)
            //{
            //    ingredientList += item + "<br />";
            //}
            string pictureUploadURL = "";
            if (fupLoad.HasFile)
            {
                pictureUploadURL = AddPicture();
            }

            string instructions = tbInstructions.Text.Replace(Environment.NewLine, "<br />");
            string ingredients = tbIngrediant.Text.Replace(Environment.NewLine, "<br />");
            if (tbPictureUrl.Text == "")
            {
                tbPictureUrl.Text = "http://admin.imbresources.org/photos/noImageFound.l.png";
            }

            if (pictureUploadURL != "")
            {
                db.Recipes.Add(
                  new Recipe{
                         Name = tbName.Text,
                         Ingredients = ingredients,
                         Instructions = instructions,
                         PictureURL = pictureUploadURL,
                         Contributer = tbContributer.Text,
                         Category = ddlCategory.SelectedValue,
                         ServingSize = tbServingSize.Text,
                         RecipeOrigin = tbOrigin.Text
                    });
            }
            else
            {
                db.Recipes.Add(
                  new Recipe{
                         Name = tbName.Text,
                         Ingredients = ingredients,
                         Instructions = instructions,
                         PictureURL = tbPictureUrl.Text,
                         Contributer = tbContributer.Text,
                         Category = ddlCategory.SelectedValue,
                         ServingSize = tbServingSize.Text,
                         RecipeOrigin = tbOrigin.Text
                    });
            }

            mvAddRecipe.ActiveViewIndex = 1;

            try
            {
                db.SaveChanges();
                lblResult.Text = "Recipe has been added.";
            }
            catch (DbEntityValidationException dbEx)
            {
                lblResult.Text = "Something bad happened, try again later.";
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
        }