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;
            }
        }
예제 #2
0
        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);
        }
예제 #4
0
        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;
 }
예제 #10
0
 public ContatoRepository(ContatoContext context)
 {
     this._context = context;
 }
예제 #11
0
 public ContatoRepositorio(ContatoContext banco)
 {
     _banco = banco;
 }
예제 #12
0
 public CidadeRepository(ContatoContext context) : base(context)
 {
 }
 public ContatosController(ContatoContext context)
 {
     _context = context;
 }
예제 #14
0
 public Repository(ContatoContext contatoContext)
 {
     _contatoContext = contatoContext;
     _dbSet          = _contatoContext.Set <T>();
 }
예제 #15
0
 public ContatosController(ContatoContext context, TelefoneContext tel, emailContext Email)
 {
     _contextCont  = context;
     _contextEmail = Email;
     _contextTel   = tel;
 }
예제 #16
0
 public ContatoRepositorio(ContatoContext ctx)
 {
     this.context = ctx;
 }