public async Task <ActionResult <Contato> > AlterarContato( [FromServices] ContatoContext context, [FromBody] Contato model) { try { if (ModelState.IsValid) { context.Contatos.Update(model); await context.SaveChangesAsync(); return(Ok()); } else { return(BadRequest(ModelState)); } } catch { return(NotFound()); throw; } }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { ContatoContext context = services.GetRequiredService <ContatoContext>(); using (DbInitializer init = new DbInitializer(context)) { init.Seed(); } } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public async Task <ActionResult <List <Contato> > > TodosContatos( [FromServices] ContatoContext context) { var contatos = await context.Contatos .ToListAsync(); return(contatos); }
static IContatoService SetConfig() { var context = new ContatoContext(); IContatoRepository repository = new ContatoRepository(context); IContatoApplication app = new ContatoApplication(repository); IContatoService service = new ContatoService(app); return(service); }
public async Task <ActionResult <Contato> > ObterContatoPorId( [FromServices] ContatoContext context , int id) { var contato = await context.Contatos .FirstOrDefaultAsync(x => x.ContatoID == id); if (contato != null) { return(Ok(contato)); } else { return(NotFound()); } }
public async Task <ActionResult <Contato> > CriarContato( [FromServices] ContatoContext context, [FromBody] Contato model) { if (ModelState.IsValid) { context.Contatos.Add(model); await context.SaveChangesAsync(); return(Ok(model.ContatoID)); } else { return(BadRequest(ModelState)); } }
public async Task <ActionResult <Contato> > ApagarContatoPorId(int id, [FromServices] ContatoContext context) { try { var contato = await context.Contatos .FirstOrDefaultAsync(x => x.ContatoID == id); context.Remove(contato); await context.SaveChangesAsync(); return(Ok()); } catch (System.Exception) { return(NotFound()); throw; } }
public EstadoRepository(ContatoContext context) : base(context) { }
public Repository(ContatoContext context) { _context = context; }
public ContatoRepository(ContatoContext context) { this._context = context; }
public ContatoRepositorio(ContatoContext banco) { _banco = banco; }
public CidadeRepository(ContatoContext context) : base(context) { }
public ContatosController(ContatoContext context) { _context = context; }
public Repository(ContatoContext contatoContext) { _contatoContext = contatoContext; _dbSet = _contatoContext.Set <T>(); }
public ContatosController(ContatoContext context, TelefoneContext tel, emailContext Email) { _contextCont = context; _contextEmail = Email; _contextTel = tel; }
public ContatoRepositorio(ContatoContext ctx) { this.context = ctx; }