void AddRabbits() { var newRabbit = new Rabbit() { Age = Int32.Parse(txtAge.Text), Name = txtName.Text }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } }
public void addRabbitToDataBase(string Name, string Age) { var newRabbit = new Rabbit() { Age = int.Parse(Age), Name = Name }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } }
private void updateRabbitDataBase(int ID, string name, string age) { //update rabbit using (var db = new RabbitDbEntities()) { Rabbit rabbitUpdate = db.Rabbits.Single(a => a.RabbitId == ID); if (rabbitUpdate != null) { rabbitUpdate.Name = name; rabbitUpdate.Age = int.Parse(age); db.SaveChanges(); } } }
private void BtnUpdateSelectedRabbit_Click(object sender, RoutedEventArgs e) { ClearDisplay(); Rabbit selectedRabbit = rabbits[RabbitsListBox.SelectedIndex]; currentRabbitID = selectedRabbit.RabbitId; Label nameLabel = AddNewGridLabel(0, 0, 1, 1, "Name: "); Label ageLabel = AddNewGridLabel(0, 0, 1, 1, "Age: "); updateNameText = AddNewGridTextBox(0, 1, 1, 1, selectedRabbit.Name); updateAgeText = AddNewGridTextBox(0, 1, 1, 1, selectedRabbit.Age.ToString()); updateNameText.Name = "updateName"; updateAgeText.Name = "updateAge"; updateNameText.VerticalAlignment = VerticalAlignment.Bottom; updateAgeText.VerticalAlignment = VerticalAlignment.Bottom; updateNameText.HorizontalAlignment = HorizontalAlignment.Left; updateAgeText.HorizontalAlignment = HorizontalAlignment.Left; nameLabel.VerticalAlignment = VerticalAlignment.Bottom; ageLabel.VerticalAlignment = VerticalAlignment.Bottom; nameLabel.HorizontalAlignment = HorizontalAlignment.Right; ageLabel.HorizontalAlignment = HorizontalAlignment.Right; Button UpdateRabbit = new Button { Content = "UPDATE", VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Center, Height = 25, Width = 200 }; Grid.SetRow(UpdateRabbit, 0); Grid.SetColumn(UpdateRabbit, 0); Grid.SetColumnSpan(UpdateRabbit, 2); UpdateRabbit.Click += UpdateRabbit_Click; ImageGrid.Children.Add(UpdateRabbit); updateNameText.Margin = new Thickness(0, 0, 0, 60); nameLabel.Margin = new Thickness(0, 0, 0, 60); updateAgeText.Margin = new Thickness(0, 0, 0, 30); ageLabel.Margin = new Thickness(0, 0, 0, 30); }
private void Button01_Click(object sender, RoutedEventArgs e) { var newRabbit = new Rabbit() { Age = Int32.Parse(AgeBox.Text), Name = NameBox.Text }; using (var db = new RabbitDbEntities()) { db.Rabbits.Add(newRabbit); db.SaveChanges(); } System.Threading.Thread.Sleep(200); PrintRabbitToBlock(); }
private void AddNewRabbit(string name, int age) { this.Title = "name"; using (var db = new RabbitDbEntities()) { List <Rabbit> rabbits = db.Rabbits.ToList(); var newRabbit = new Rabbit() { Age = age, Name = $"{name}" }; db.Rabbits.Add(newRabbit); db.SaveChanges(); listBox.Items.Add(newRabbit.Name); } }