public ActionResult Save(PatchModel model) { if (model.Id == 0) { //create Patch p = PatchModelHelper.ConvertTo(model); PatchManager patchManager = new PatchManager(); patchManager.Create(p); return(RedirectToAction("Index", "Patch")); } else { //update Patch p = PatchModelHelper.ConvertTo(model); PatchManager patchManager = new PatchManager(); Patch patch = patchManager.Get(p.Id); if (patch != null) { patch.Height = p.Height; patch.Width = p.Width; patch.NutrientClaim = p.NutrientClaim; patch.LocationType = p.LocationType; patch.Name = p.Name; patch.Description = p.Description; patchManager.Update(patch); } } return(View("PatchEdit", model)); }
public ActionResult Patch() { try { SubjectManager subjectManager = new SubjectManager(); PatchManager patchManager = new PatchManager(); Patch patch = new Patch(); patch.Name = "test"; patch.Width = 800; patch.Height = 800; Plant plant = new Plant(); plant = subjectManager.GetAll <Plant>().FirstOrDefault(); Placement p = new Placement() { Plant = plant, Transformation = "matrix(1,0,0,1,300,100)", PlantingArea = TimePeriodArea.Anfang, PlantingMonth = TimePeriodMonth.August, Patch = patch }; patch.PatchElements.Add(p); patchManager.Create(patch); p = new Placement() { Plant = plant, Transformation = "matrix(1,0,0,1,300,600)", PlantingArea = TimePeriodArea.Anfang, PlantingMonth = TimePeriodMonth.August, Patch = patch }; patch.PatchElements.Add(p); patchManager.Update(patch); //patch.PatchElements.Remove(p); //patchManager.Update(patch); //Patch patchFromDB = patchManager.GetAll<Patch>().LastOrDefault(); //patchManager.Delete(patchFromDB); } catch (Exception ex) { throw ex; } BeetModel model = new BeetModel(); //test Pflanze 1 PflanzenModel p1 = new PflanzenModel() { Name = "Blumenkohl", X = 0, Y = 0 }; PflanzenModel p2 = new PflanzenModel() { Name = "Tomate", X = 500, Y = 200 }; model.Pflanzen.Add(p1); model.Pflanzen.Add(p2); return(View("Beet", model)); }