public async Task <IActionResult> Edit(int id, [Bind("Id,CompradorId,VendedorId")] VendedorFavorito vendedorFavorito) { if (id != vendedorFavorito.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(vendedorFavorito); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VendedorFavoritoExists(vendedorFavorito.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CompradorId"] = new SelectList(_context.Usuario, "Id", "Apellido", vendedorFavorito.CompradorId); ViewData["VendedorId"] = new SelectList(_context.Usuario, "Id", "Apellido", vendedorFavorito.VendedorId); return(View(vendedorFavorito)); }
public async Task <IActionResult> Create([Bind("Id,CompradorId,VendedorId")] VendedorFavorito vendedorFavorito) { if (ModelState.IsValid) { _context.Add(vendedorFavorito); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CompradorId"] = new SelectList(_context.Usuario, "Id", "Apellido", vendedorFavorito.CompradorId); ViewData["VendedorId"] = new SelectList(_context.Usuario, "Id", "Apellido", vendedorFavorito.VendedorId); return(View(vendedorFavorito)); }
public void Favorito([Bind("Id,CompradorId,VendedorId")] VendedorFavorito vendedorFavorito) { var id = _context.VendedorFavorito.FirstOrDefaultAsync(m => m.VendedorId == vendedorFavorito.VendedorId && m.CompradorId == vendedorFavorito.CompradorId).Result; if (id != null) { _context.VendedorFavorito.Remove(id); } else { _context.Add(vendedorFavorito); } _context.SaveChanges(); }