[Authorize] public ActionResult Edit(Fenotype obj) { try { if (ModelState.IsValid) { dbActionResult resultAction = new dbActionResult(); resultAction = db.EditFenotype(obj); int id = resultAction.intResult; if (id >= 0) { return(RedirectToAction("Index")); } if (id == -1) { db.DetachFenotype(obj); Fenotype oldObj = db.GetFenotype(obj.FenotypeID); ModelState.AddModelError("", "Ошибка параллельного доступа к данным. Если проблема повторится, обратитесь к системному администратору."); if (oldObj.Code != obj.Code) { ModelState.AddModelError("Code", "Текущее значение: " + oldObj.Code.ToString()); } if (oldObj.DescriptionEng != obj.DescriptionEng) { ModelState.AddModelError("DescriptionEng", "Текущее значение: " + oldObj.DescriptionEng.ToString()); } if (oldObj.DescriptionRus.ToString() != obj.DescriptionRus.ToString()) { ModelState.AddModelError("DescriptionRus", "Текущее значение: " + oldObj.DescriptionRus.ToString()); } obj.Timestamp = oldObj.Timestamp; } if (id == -2) { ModelState.AddModelError("", resultAction.exData.Message.ToString() + " | " + resultAction.exData.GetType().ToString() + " | " + "Невозможно сохранить изменения. Нажмите обновить страницу и повторить действия. Если проблема повторится, обратитесь к системному администратору."); } } } catch (DataException ex) { ModelState.AddModelError("", ex.Message.ToString() + " | " + ex.GetType().ToString() + " | " + "Невозможно сохранить изменения. Попробуйте повторить действия. Если проблема повторится, обратитесь к системному администратору."); } return(View(obj)); }
[Authorize] public ActionResult Create(Fenotype obj) { try { if (ModelState.IsValid) { int id = db.AddFenotype(obj); return(RedirectToAction("Index")); } } catch (DataException ex) { ModelState.AddModelError("", ex.Message.ToString() + " Невозможно сохранить изменения. Попробуйте повторить действия. Если проблема повторится, обратитесь к системному администратору."); } return(RedirectToAction("Index")); }
//Add a fenotype to the selected plant (Jim) public void AddPhenotype(Plant plant, int leafSize, string leafShape, string ratioBloomLeaf, string Bloom, string habitus, string lifeForm, string sprout) { var fenotypePlant = new Fenotype { PlantId = plant.PlantId, Bladgrootte = leafSize, Bladvorm = leafShape, RatioBloeiBlad = ratioBloomLeaf, Bloeiwijze = Bloom, Habitus = habitus, Levensvorm = lifeForm, Spruitfenologie = sprout }; _context.Fenotype.Add(fenotypePlant); _context.SaveChanges(); }
public string EditPlantData(long plantId, Fenotype fenotype, List <FenotypeMulti> fenotypeMulti, Abiotiek abiotiek, List <AbiotiekMulti> abiotiekMulti, List <Commensalisme> commensalisme, List <CommSocialbiliteit> commSocialbiliteit, List <CommLevensvorm> commLevensvorm, ExtraEigenschap extraEigenschap, TfgsvType type, TfgsvFamilie familie, TfgsvGeslacht geslacht, TfgsvSoort soort, TfgsvVariant variant, string plantDichtheidMin, string plantDichtheidMax) { string result = "Plant werd aangepast"; try { //fenotype var dbFenotype = context.Fenotype.FirstOrDefault(f => f.PlantId == fenotype.PlantId); dbFenotype = fenotype; //abiotiek var dbAbiotiek = context.Abiotiek.FirstOrDefault(a => a.PlantId == abiotiek.PlantId); dbAbiotiek = abiotiek; context.AbiotiekMulti.RemoveRange(GetAbiotiekMulti(plantId)); context.AbiotiekMulti.AddRange(abiotiekMulti); //commensalisme context.Commensalisme.RemoveRange(GetCommStrategieFromPlant(plantId)); context.Commensalisme.AddRange(commensalisme); var dbSocial = context.CommensalismeMulti.Where(c => c.Eigenschap == "Sociabiliteit"); var dbLeven = context.CommensalismeMulti.Where(c => c.Eigenschap == "Levensvorm"); context.CommensalismeMulti.RemoveRange(dbSocial.Where(c => c.PlantId == plantId)); context.CommensalismeMulti.RemoveRange(dbLeven.Where(c => c.PlantId == plantId)); foreach (var socialbiliteit in commSocialbiliteit) { context.CommensalismeMulti.Add(new CommensalismeMulti() { PlantId = plantId, Eigenschap = "Sociabiliteit", Waarde = socialbiliteit.Sociabiliteit }); } foreach (var levensvorm in commLevensvorm) { context.CommensalismeMulti.Add(new CommensalismeMulti() { PlantId = plantId, Eigenschap = "Levensvorm", Waarde = levensvorm.Levensvorm }); } //extra eigenschappen var dbExtra = context.ExtraEigenschap.FirstOrDefault(e => e.PlantId == extraEigenschap.PlantId); dbExtra = extraEigenschap; //plant var dbPlant = GetPlantWithId(plantId); dbPlant.Type = type.Planttypenaam; dbPlant.Familie = familie.Familienaam; dbPlant.Geslacht = geslacht.Geslachtnaam; dbPlant.Soort = soort.Soortnaam; dbPlant.Variant = variant.Variantnaam; string fgsv = familie.Familienaam + " " + geslacht.Geslachtnaam; if (soort.Soortnaam != null) { fgsv += " " + soort.Soortnaam; } if (variant.Variantnaam != null) { fgsv += " " + variant.Variantnaam; } dbPlant.Fgsv = fgsv; if (plantDichtheidMin == String.Empty) { dbPlant.PlantdichtheidMin = null; } else { dbPlant.PlantdichtheidMin = short.Parse(plantDichtheidMin); } if (plantDichtheidMax == String.Empty) { dbPlant.PlantdichtheidMax = null; } else { dbPlant.PlantdichtheidMax = short.Parse(plantDichtheidMax); } dbPlant.TypeId = (int?)type.Planttypeid; dbPlant.FamilieId = (int?)familie.FamileId; if (soort.Soortid == 0) { dbPlant.SoortId = null; } else { dbPlant.SoortId = (int?)soort.Soortid; } if (variant.VariantId == 0) { dbPlant.VariantId = null; } else { dbPlant.VariantId = (int?)variant.VariantId; } context.FenotypeMulti.AddRange(fenotypeMulti); context.SaveChanges(); } catch (Exception e) { result = e + "\nEr is een fout opgetreden tijdens het opslaan, gelieve contact op te nemen met de beheerders van Plantify"; } return(result); }
// // GET: /Fenotype/Edit/5 [Authorize] public ActionResult Edit(int id) { Fenotype obj = db.GetFenotype(id); return(View(obj)); }