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(); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new UPBEatsContext( serviceProvider.GetRequiredService < DbContextOptions <UPBEatsContext> >())) { // Buscando cualquier rol if (context.Rol.Any()) { return; // Ya se inicializó la BD } //Roles agregar context.Rol.AddRange( new Rol { Nombre = "Comprador" }, new Rol { Nombre = "Vendedor" } ); context.SaveChanges(); } }