public ActionResult New(NewCartonForm form) { if (!ModelState.IsValid) { return RedirectToAction<CartonController>(c => c.New()) .WithError("Invalid Input!"); } _context.Cartons.Add(new Carton { ItemId = form.ItemId, NumberOfPieces = form.NumberOfPieces }); _context.SaveChanges(); return RedirectToAction<CartonController>(c => c.Index()) .WithSuccess("Carton created!"); }
public ActionResult New() { var alreadySetupInCartonItems = _context.Cartons.Select(c => c.ItemId).ToArray(); var form = new NewCartonForm { //ItemList = // _context.Items.ToListItems(t => (t.ItemCode + " - " + t.ItemName), // v => v.ItemId.ToString(CultureInfo.InvariantCulture), "Please Select...") ItemList = _context.Items.Where(i => !alreadySetupInCartonItems.Contains(i.ItemId)).ToListItems(t => (t.ItemCode + " - " + t.ItemName), v => v.ItemId.ToString(CultureInfo.InvariantCulture), "Please Select...") }; return View(form); }