Beispiel #1
0
        public IActionResult SowField(int id, string seed)
        {
            TempData["seedval"] = seed;
            _db.Plant.AddRange(new Plant {
                Colour = seed
            });
            _db.SaveChanges();
            int currentPlantId = _db.Plant.ToList().Last().Id;

            // Field field = _db.Field.Where(x => x.Id == id).FirstOrDefault();
            //int fieldIndex = _db.Field.ToList().IndexOf(field);

            // find field of chosen index and assign plant to it
            _db.Field.ToList()[_db.Field.ToList().FindIndex(x => x.Id == id)].PlantId = currentPlantId;
            _db.SaveChanges();


            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public IActionResult Upsert()
 {
     if (ModelState.IsValid)
     {
         if (Seed.Id == 0)
         {
             //create
             _db.Seeds.Add(Seed);
         }
         else
         {
             _db.Seeds.Update(Seed);
         }
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(Seed));
 }