示例#1
0
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            dataEntities.Database.ExecuteSqlCommand("DELETE FROM Skladniki WHERE IdPotrawy=" + p.IdPotrawy);

            p.NazwaPotrawy  = NameTextBox.Text;
            p.Skladniki     = IngTextBox.Text;
            p.Przygotowanie = PrepTextBox.Text;

            dataEntities.Entry(p).State = EntityState.Modified;
            dataEntities.SaveChanges();

            Skladniki ingridient = new Skladniki();

            string[] ingr = System.Text.RegularExpressions.Regex.Split(p.Skladniki, "\r\n");

            ingridient.IdPotrawy = p.IdPotrawy;
            foreach (string i in ingr)
            {
                ingridient.Skladnik = i;
                dataEntities.Entry(ingridient).State = EntityState.Added;
                dataEntities.SaveChanges();
            }

            this.Close();
        }
示例#2
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            Potrawy recipe = new Potrawy();

            recipe.NazwaPotrawy  = NameTextBox.Text;
            recipe.Skladniki     = IngTextBox.Text;
            recipe.Przygotowanie = PrepTextBox.Text;

            try
            {
                using (var dbCtx = new KitchenEntities1())
                {
                    dbCtx.Entry(recipe).State = EntityState.Added;
                    dbCtx.SaveChanges();

                    Skladniki ingridient = new Skladniki();
                    string[]  ingr       = System.Text.RegularExpressions.Regex.Split(recipe.Skladniki, "\r\n");

                    ingridient.IdPotrawy = recipe.IdPotrawy;
                    foreach (string i in ingr)
                    {
                        ingridient.Skladnik           = i;
                        dbCtx.Entry(ingridient).State = EntityState.Added;
                        dbCtx.SaveChanges();
                    }
                }
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Added failed");
            }
        }