コード例 #1
0
        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();
        }
コード例 #3
0
        public async Task <ActionResult <List <Contato> > > TodosContatos(
            [FromServices] ContatoContext context)
        {
            var contatos = await context.Contatos
                           .ToListAsync();

            return(contatos);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: andreleaos/TesteEF6
        static IContatoService SetConfig()
        {
            var context = new ContatoContext();
            IContatoRepository  repository = new ContatoRepository(context);
            IContatoApplication app        = new ContatoApplication(repository);
            IContatoService     service    = new ContatoService(app);

            return(service);
        }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
 public EstadoRepository(ContatoContext context) : base(context)
 {
 }
コード例 #9
0
 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)
 {
 }
コード例 #13
0
 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;
 }