private void AddLocation_Click(object sender, EventArgs e) { Planting p = new Planting(); p.IssueImage = JsonConvert.DeserializeObject <string>(Intent.GetStringExtra("objtopass")); Control.DataOper.PutData <Issuelocationpickup_PlantingCompaign>(this, p); }
protected override void SetValues(GardenArea area) { Planting planting = area as Planting; planting.Varieties = this.Varieties; //TODO change planting info here base.SetValues(area); }
private void SetUpVarieties(Planting planting) { string[] labels = new string[Varieties.Count]; keys = new VarietyKeySeq[Varieties.Count]; var en = Varieties.Keys.GetEnumerator(); for (int i = 0; en.MoveNext() && i < Varieties.Count; i++) { keys[i] = en.Current; labels[i] = GardenData.LoadedData.GetVariety(en.Current).Name + " x " + Varieties[en.Current].Count; } VarityBox = new ComboBoxEntry(labels); VarityBox.Changed += (object sender, EventArgs e) => { VarietyRemoveButton.Sensitive = VarityBox.Active >= 0; VarietyEditButton.Sensitive = VarityBox.Active >= 0; }; if (VarietiesLabeledHBox != null) { VarietiesInnerHBox.Remove(VarietyRemoveButton); VarietiesInnerHBox.Remove(VarietyEditButton); RemoveLabeledEntry(VarietiesLabeledHBox); } VarietyRemoveButton = new Button("Remove"); VarietyRemoveButton.Sensitive = false; VarietyRemoveButton.Clicked += (object sender, EventArgs e) => { Varieties.Remove(keys[VarityBox.Active]); SetUpVarieties(planting); }; VarietyEditButton = new Button("Edit"); VarietyEditButton.Sensitive = false; VarietyEditButton.Clicked += (sender, e) => { EditPlantingInfoWindow.ShowPlantingInfoWindow(Varieties[keys[VarityBox.Active]], (plantingInfo) => { GardenDrawingArea area = GardenDrawingArea.ActiveInstance; area.Draw(); MainWindow.GetInstance().ShowAreaSelectionInfo(area.SelectedArea); }, planting, GardenData.LoadedData.GetVariety(keys[VarityBox.Active]).Name); }; VarietiesInnerHBox = new HBox(); VarietiesInnerHBox.Add(VarityBox); VarietiesInnerHBox.Add(VarietyEditButton); VarietiesInnerHBox.Add(VarietyRemoveButton); VarietiesLabeledHBox = AddLabeledEntry("Varieties", VarietiesInnerHBox); ShowAll(); }
protected PlantingCreationDialog(string title, Planting planting) : base(title) { Varieties = new Dictionary <VarietyKeySeq, PlantingInfo>(); foreach (KeyValuePair <VarietyKeySeq, PlantingInfo> pair in planting.Varieties) { Varieties.Add(pair.Key, new PlantingInfo(pair.Value)); } SetUpVarieties(planting); ShowAll(); }
public static void ShowPlantingCreationDialog(List <GardenPoint> points, Action <Planting> action) { PlantingCreationDialog dialog = new PlantingCreationDialog("Create planting"); GardenDrawingArea.ActiveInstance?.Draw(); dialog.CreateButton.Clicked += (object sender, System.EventArgs e) => { Planting area = new Planting(dialog.NameEntry.Text, dialog.DescrEntry.Text); dialog.SetValuesForCreation(area, points); action(area); GardenDrawingArea.ActiveInstance?.Draw(); dialog.Destroy(); }; }
public ActionResult PlantCrop(PlantingViewModel model) { if (ModelState.IsValid) { var planting = new Planting { DatePlanted = model.DatePlanted, ExpectedHarvestDate = model.DatePlanted.AddMonths(model.MonthToGrowId) }; _plantingService.Create(planting); return(RedirectToAction("Index", "FarmCrop")); } return(RedirectToAction("Index", "FarmCrop")); }
public ActionResult UdatePlanting(int?id) { PlantingViewModel model = null; var config = new MapperConfiguration(cfg => { cfg.CreateMap <Planting, PlantingViewModel>(); }); IMapper iMapper = config.CreateMapper(); Planting editPlanting = PlantingService.GetById(id); model = iMapper.Map <Planting, PlantingViewModel>(editPlanting); model.MonthToGrowId = editPlanting.ExpectedHarvestDate.Month - editPlanting.DatePlanted.Month; model.HarvestPeriodDropDown = GetCropDueMonth(model.MonthToGrowId); return(PartialView("_AddCropPlantingDialog", model)); }
public ActionResult PlantCrop(PlantingViewModel model) { if (ModelState.IsValid) { if (model.Id > 0) { Planting existingplanting = PlantingService.GetById(model.Id); existingplanting.DatePlanted = model.DatePlanted; existingplanting.ExpectedHarvestDate = model.DatePlanted.AddMonths(model.MonthToGrowId); PlantingService.Update(existingplanting); return(RedirectToAction("Index", "Crop")); } Planting planting = new Planting { DatePlanted = model.DatePlanted, ExpectedHarvestDate = model.DatePlanted.AddMonths(model.MonthToGrowId), FarmCropId = model.Id }; planting = PlantingService.Create(planting); if (planting != null) { FarmCrop updateFarmCrop = FarmCropService.GetById(model.FarmCropId); updateFarmCrop.PlantingId = planting?.Id; FarmCropService.Update(updateFarmCrop); } return(RedirectToAction("Index", "Crop")); } return(RedirectToAction("Index", "Crop")); }
public void Update(Planting planting) { repository.Update(planting); }
public void Insert(Planting planting) { repository.Insert(planting); }
public static void ShowPlantingEditDialog(Planting area) { PlantingCreationDialog dialog = new PlantingCreationDialog("Edit planting '" + area.Name + "'", area); dialog.SetValuesForEdit(area); }
/// <summary> /// Shows the planting info window for new varieties. /// </summary> /// <param name="action">Action.</param> /// <param name="planting">Planting.</param> /// <param name="varietyName">Variety name.</param> public static void ShowPlantingInfoWindow(System.Action <PlantingInfo> action, Planting planting, string varietyName) => ShowPlantingInfoWindow(new PlantingInfo() { PlannedPlantingDate = planting.created, PlantingDate = planting.created }, action, planting, varietyName);
/// <summary> /// Shows the planting info window for varities that already have been added to a planting. /// </summary> /// <param name="plantingInfo">Planting info.</param> /// <param name="action">Action.</param> /// <param name="planting">Planting.</param> /// <param name="varietyName">Variety name.</param> public static void ShowPlantingInfoWindow(PlantingInfo plantingInfo, System.Action <PlantingInfo> action, Planting planting, string varietyName) { EditPlantingInfoWindow window = new EditPlantingInfoWindow(plantingInfo, action); window.Title = $"Add {varietyName} to {planting.Name}"; window.ShowAll(); }
// POST api/<controller> public HttpResponseMessage Post([FromBody] Planting planting) { try { var parcelArea = planting.Parcel.ParcelAreas.FirstOrDefault(); if (parcelArea != null && parcelArea.MetricUnit == null) { parcelArea.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == Context.Parcels.FirstOrDefault(p => p.Id == planting.Parcel.Id).ParcelAreas.FirstOrDefault().MetricUnit.Id); planting.Parcel.ParcelAreas = new List <ParcelArea>() { parcelArea }; } if (planting.PlantingCrops != null && planting.PlantingCrops.Count > 0) { foreach (var plantingCrop in planting.PlantingCrops) { plantingCrop.Crop = Context.Crops.FirstOrDefault(c => c.Id == plantingCrop.Crop.Id); plantingCrop.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == plantingCrop.MetricUnit.Id); } } if (planting.PlantingFertilizers != null && planting.PlantingFertilizers.Count > 0) { foreach (var plantingFertilizer in planting.PlantingFertilizers) { plantingFertilizer.Fertilizer = Context.Fertilizers.FirstOrDefault(f => f.Id == plantingFertilizer.Fertilizer.Id); plantingFertilizer.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == plantingFertilizer.MetricUnit.Id); } } if (planting.Yields != null && planting.Yields.Count > 0) { foreach (var yield in planting.Yields) { yield.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == yield.MetricUnit.Id); } } var tempParcel = Context.Parcels.Include(p => p.ParcelAreas).FirstOrDefault(p => p.Id == planting.Parcel.Id); if (tempParcel != null) { tempParcel.GruntId = planting.Parcel.GruntId; tempParcel.Name = planting.Parcel.Name; tempParcel.OwnerName = planting.Parcel.OwnerName; var tempParcelAreas = tempParcel.ParcelAreas.ToList(); var tempPlantingParcelAreas = planting.Parcel.ParcelAreas.ToList(); for (int i = 0; i < tempParcelAreas.Count; i++) { var muId = tempPlantingParcelAreas[i].MetricUnit.Id; tempParcelAreas[i].MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == muId); tempParcelAreas[i].Quantity = tempPlantingParcelAreas[i].Quantity; } tempParcel.ParcelAreas = tempParcelAreas; planting.Parcel = tempParcel; } Context.Plantings.AddOrUpdate(planting); Context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, true)); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ExceptionMessageHelper.GetErrorMessage(ex))); } }
// PUT api/<controller>/5 public HttpResponseMessage Put(int id, [FromBody] Planting planting) { try { var dbQuery = from p in Context.Plantings .Include(p => p.PlantingCrops.Select(pc => pc.MetricUnit)) .Include(p => p.PlantingCrops.Select(pc => pc.Crop)) .Include(p => p.PlantingFertilizers.Select(pa => pa.MetricUnit)) .Include(p => p.PlantingFertilizers.Select(pa => pa.Fertilizer)) .Include(p => p.Yields) .Include(p => p.Yields.Select(py => py.MetricUnit)) .Where(p => p.Id == id) select p; var existingRecord = dbQuery.FirstOrDefault(); Context.Entry(existingRecord).CurrentValues.SetValues(planting); if (existingRecord != null) { existingRecord.Season = planting.Season; #region Update PlantingCrops var plantingCropsToRemove = existingRecord.PlantingCrops.Where(existingPlantingCrop => planting.PlantingCrops.All(pc => !ObjectComparisonHelper.AreEqual(pc, existingPlantingCrop))).ToList(); if (plantingCropsToRemove.Count > 0) { foreach (var plantingCropToRemove in plantingCropsToRemove) { existingRecord.PlantingCrops.Remove(plantingCropToRemove); } } foreach (var plantingCrop in planting.PlantingCrops) { if (existingRecord.PlantingCrops.All(pc => !ObjectComparisonHelper.AreEqual(pc, plantingCrop))) { plantingCrop.Crop = Context.Crops.FirstOrDefault(c => c.Id == plantingCrop.Crop.Id); plantingCrop.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == plantingCrop.MetricUnit.Id); existingRecord.PlantingCrops.Add(plantingCrop); } } #endregion #region Update PlantingFertilizers var plantingFertilizersToRemove = existingRecord.PlantingFertilizers.Where(existingPlantingFertilizer => planting.PlantingFertilizers.All(pf => !ObjectComparisonHelper.AreEqual(pf, existingPlantingFertilizer))).ToList(); if (plantingFertilizersToRemove.Count > 0) { foreach (var plantingFertilizerToRemove in plantingFertilizersToRemove) { existingRecord.PlantingFertilizers.Remove(plantingFertilizerToRemove); } } foreach (var plantingFertilizer in planting.PlantingFertilizers) { if (existingRecord.PlantingFertilizers.All(pf => !ObjectComparisonHelper.AreEqual(pf, plantingFertilizer))) { plantingFertilizer.Fertilizer = Context.Fertilizers.FirstOrDefault(c => c.Id == plantingFertilizer.Fertilizer.Id); plantingFertilizer.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == plantingFertilizer.MetricUnit.Id); existingRecord.PlantingFertilizers.Add(plantingFertilizer); } } #endregion #region Update Yields var yieldsToRemove = existingRecord.Yields.Where(existingYield => planting.Yields.All(y => !ObjectComparisonHelper.AreEqual(y, existingYield))).ToList(); if (yieldsToRemove.Count > 0) { foreach (var yieldToRemove in yieldsToRemove) { existingRecord.Yields.Remove(yieldToRemove); } } foreach (var yield in planting.Yields) { if (existingRecord.Yields.All(y => !ObjectComparisonHelper.AreEqual(y, yield))) { yield.MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == yield.MetricUnit.Id); existingRecord.Yields.Add(yield); } } #endregion var tempParcel = Context.Parcels.Include(p => p.ParcelAreas).FirstOrDefault(p => p.Id == planting.Parcel.Id); if (tempParcel != null) { tempParcel.GruntId = planting.Parcel.GruntId; tempParcel.Name = planting.Parcel.Name; tempParcel.OwnerName = planting.Parcel.OwnerName; var tempParcelAreas = tempParcel.ParcelAreas.ToList(); var tempPlantingParcelAreas = planting.Parcel.ParcelAreas.ToList(); for (int i = 0; i < tempParcelAreas.Count; i++) { var muId = tempPlantingParcelAreas[i].MetricUnit.Id; tempParcelAreas[i].MetricUnit = Context.MetricUnits.FirstOrDefault(mu => mu.Id == muId); tempParcelAreas[i].Quantity = tempPlantingParcelAreas[i].Quantity; } tempParcel.ParcelAreas = tempParcelAreas; existingRecord.Parcel = tempParcel; } Context.Plantings.AddOrUpdate(existingRecord); Context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, true)); } throw new Exception("Planting with id " + id + " not found."); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, ExceptionMessageHelper.GetErrorMessage(ex))); } }
public static GardenData TestData() { GardenData Data = new GardenData("testdata"); var zwiebelgewaechse = new PlantFamily("Zwiebelgewaechse", ""); Data.AddFamily("zwiebelgewaechse", zwiebelgewaechse); var knoblauch = new Plant("Knoblauch", ""); knoblauch.FeederType = FeederType.Medium; knoblauch.ScientificName = "allium sativum"; zwiebelgewaechse.AddPlant("knoblauch", knoblauch); var morado = new PlantVariety("Morado", "rotviolett, aus Spanien, geeignet für Herbstpflanzung, bildet Brutzwiebeln"); morado.SetColor(new Cairo.Color(0.9, 0.9, 0.9)); knoblauch.AddVariety("morado", morado); var vallelado = new PlantVariety("Vallelado", "bla"); vallelado.SetColor(new Cairo.Color(0.9, 0.9, 0.9)); knoblauch.AddVariety("vallelado", vallelado); var nachtschattengew = new PlantFamily("Nachtschattengewächse", ""); Data.AddFamily("nachtschattengewaechse", nachtschattengew); var kartoffeln = new Plant("Kartoffel", ""); kartoffeln.SetColor(new Cairo.Color(0.2, 0.8, 0.8)); nachtschattengew.AddPlant("kartoffel", kartoffeln); var bed1 = new Garden.Garden("Omas Garten", "Alte Garten von Oma", 2000, 1, 2000, 1); var bed2 = new Garden.Garden("Hauptstraßengarten", "Alte Garten von Oma", 2000, 1, 2000, 1); Data.AddGarden("oma_garten", bed1); Data.AddGarden("hptstr_garten", bed2); bed1.Shape.AddPoint(new GardenPoint(0, 0)); bed1.Shape.AddPoint(new GardenPoint(0, 200)); bed1.Shape.AddPoint(new GardenPoint(300, 200)); bed1.Shape.AddPoint(new GardenPoint(300, 0)); bed1.Shape.FinishPoints(); var compostArea = new GardenArea("Kompost", "hier wurde Kompost angewendet", 2000, 1, 2010, 6); compostArea.Shape.AddPoint(new GardenPoint(100, 100)); compostArea.Shape.AddPoint(new GardenPoint(300, 100)); compostArea.Shape.AddPoint(new GardenPoint(300, 200)); compostArea.Shape.AddPoint(new GardenPoint(100, 200)); compostArea.Shape.FinishPoints(); bed1.AddMethodArea("compost", compostArea); var plantingArea = new Planting("Planting", "hier wurde was gepflanzt", 2000, 1, 2010, 6); plantingArea.Shape.AddPoint(new GardenPoint(400, 400)); plantingArea.Shape.AddPoint(new GardenPoint(500, 400)); plantingArea.Shape.AddPoint(new GardenPoint(500, 500)); plantingArea.Shape.AddPoint(new GardenPoint(400, 500)); plantingArea.Shape.FinishPoints(); bed1.AddPlanting("planting", plantingArea); plantingArea.AddVariety(morado, new PlantingInfo() { Count = 3 }); plantingArea.AddVariety(vallelado, new PlantingInfo() { Count = 2 }); //string s = Newtonsoft.Json.JsonConvert.SerializeObject(Data, Newtonsoft.Json.Formatting.Indented); return(Data); }
public void Put(int id, [FromBody] Planting value) { var planting = service.Put <PlantingValidator>(value); }
public void Post([FromBody] Planting value) { var planting = service.Post <PlantingValidator>(value); }