public IActionResult SaveAllergenItem(AllergenItemViewModel i) { if (i.IsChoosed == true) { var k = _context.AllergenItems.Where(l => l.ItemId == i.ItemId).Where(f => f.AllergenId == i.AllergenId).FirstOrDefault(); if (k == null) { var n = new AllergenItem(); n.AllergenId = i.AllergenId; n.ItemId = i.ItemId; _context.Add(n); _context.SaveChanges(); } } else { var k = _context.AllergenItems.Where(l => l.ItemId == i.ItemId).Where(f => f.AllergenId == i.AllergenId).FirstOrDefault(); if (k != null) { _context.Remove(k); _context.SaveChanges(); } } return(Ok(i)); }
public IActionResult ChooseAllergen(AllergenItem allergenItem) { _context.Add(allergenItem); _context.SaveChanges(); return(Ok(allergenItem)); }