private void buttonAddDish_Click(object sender, RoutedEventArgs e) { Food f = new Food(); MyPlate mp = new MyPlate(); if (ProductComboBox.SelectedItem != null) { f = SelectedItem(ProductComboBox.SelectedValue.ToString()); } else { MessageBox.Show("Блюдо должно быть указано обязательно!"); return; } if (f == null || String.IsNullOrEmpty(WeightTextBox.Text) == true) { MessageBox.Show("Блюдо и его вес должны быть указаны обязательно!"); return; } else { int parsed = -1; if (int.TryParse(WeightTextBox.Text, out parsed) == true) { } else { MessageBox.Show("Некорректно введены данные!"); return; } } int h = 0; int m = 0; int s = 0; try { h = Int32.Parse(comboBoxHour.SelectedValue.ToString().Split(':')[1]); m = Int32.Parse(comboBoxMinutes.SelectedValue.ToString().Split(':')[1]); mp = new MyPlate { mealtime = new DateTime(MealTimePicker.SelectedDate.Value.Year, MealTimePicker.SelectedDate.Value.Month, MealTimePicker.SelectedDate.Value.Day, h, m, s), }; myplateRep.Add(mp); } catch (NullReferenceException) { MessageBox.Show("Не указано время!"); return; } platefoodrecordRepositoryRep.Add(new PlateFoodRecord { FoodId = f.Id, PlateId = mp.Id, Weight = float.Parse(WeightTextBox.Text) }); MessageBox.Show("Блюдо в тарелке!"); }
public MyPlate Remove(MyPlate myplate) { _context.Set <MyPlate>().Remove(myplate); _context.SaveChanges(); return(myplate); }
public MyPlate Add(MyPlate myplate) { _context.Set <MyPlate>().Add(myplate); _context.SaveChanges(); return(myplate); }