private void button_Click(object sender, RoutedEventArgs e) { Soil selectedSoil = soilComboBox.SelectedItem as Soil; Fertilizer selectedFertilizer = fertilizerComboBox.SelectedItem as Fertilizer; try { selectedFertilizer.Count = int.Parse(FertilizerCountText.Text); Models.Model.Condition condition = new Models.Model.Condition(); condition.MinTmp = double.Parse(plantMinTempText.Text); condition.MaxTmp = double.Parse(plantMaxTempText.Text); condition.MinHumidity = double.Parse(plantHumidityMinText.Text); condition.MaxHumidity = double.Parse(plantHumidityMaxText.Text); condition.phMin = double.Parse(plantPhminText.Text); condition.phMax = double.Parse(plantPhmaxText.Text); Plant plant = new Plant(); plant.Name = plantNameText.Text; plant.Price = double.Parse(plantPriceText.Text); if (selectedFertilizer != null || selectedSoil != null || condition.MinTmp < condition.MaxTmp || condition.MinHumidity < condition.MaxHumidity || condition.phMin < condition.phMax || plant.Price != 0 || !string.IsNullOrEmpty(plant.Name)) { MainWindow.channel.AddPlant(plant, condition, selectedSoil, selectedFertilizer); } MessageBox.Show(plantNameText.Text + " added!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void AddPlant(Plant plant, Models.Model.Condition condition, Soil soil, Fertilizer fertilizer) { int conditionId = conditionRepository.AddCondition(condition, soil.SoilId); fertilizerRepository.AddFertilizerCondition(fertilizer.FertilizerId, conditionId, fertilizer.Count); plantRepository.AddPlant(plant, 2); }