public async Task <IActionResult> Create([Bind("CollectionREPPID,ReppID,OperativeID")] CollectionREPP collectionREPP) { var items = Request.Form["SelectedRepp"]; _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.CollectionsREPP ON"); if (ModelState.IsValid) { foreach (var item in items) { int reppID = Convert.ToInt32(item); if (!CollectionREPPExists(collectionREPP.OperativeID, reppID)) { CollectionREPP c = new CollectionREPP() { ReppID = reppID, OperativeID = collectionREPP.OperativeID }; _context.CollectionsREPP.Add(c); } } _toastNotification.AddSuccessToastMessage("Coleccion de repps añadida exitosamente"); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["OperativeID"] = new SelectList(_context.Operative, "OperativeID", "Name", collectionREPP.OperativeID); ViewData["ReppID"] = new SelectList(_context.REPPS, "ReppID", "Name", collectionREPP.ReppID); return(View(collectionREPP)); }
public async Task <IActionResult> Edit(int id, [Bind("CollectionREPPID,ReppID,OperativeID")] CollectionREPP collectionREPP) { if (id != collectionREPP.CollectionREPPID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(collectionREPP); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CollectionREPPExists(collectionREPP.CollectionREPPID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["OperativeID"] = new SelectList(_context.Operative, "OperativeID", "Name", collectionREPP.OperativeID); ViewData["ReppID"] = new SelectList(_context.REPPS, "ReppID", "Name", collectionREPP.ReppID); return(View(collectionREPP)); }