Example #1
0
        public void GetContaPagar()
        {
            var options = new DbContextOptionsBuilder <ContaContext>()
                          .UseInMemoryDatabase(databaseName: "WebAPI")
                          .Options;

            using (var context = new ContaContext(options))
            {
                context.Add(new Conta
                {
                    Nome           = "Conta 01",
                    ValorOriginal  = 100,
                    DataVencimento = Convert.ToDateTime("2021-01-01"),
                    DataPagamento  = Convert.ToDateTime("2021-01-20")
                });

                context.SaveChanges();
            }

            using (var context = new ContaContext(options))
            {
                ContaPagarController contaPagarController = new ContaPagarController(context);

                var result = contaPagarController.Get() as ObjectResult;

                var contas = Assert.IsType <List <Conta> >(result.Value);
                Assert.True(contas.Count > 0);
            }
        }
        public IActionResult Post([FromBody] Conta conta)
        {
            if (conta == null)
            {
                return(BadRequest("Conta é null."));
            }

            if (conta.IsValid())
            {
                conta.Calcular();
                _contaContext.Add(conta);
                _contaContext.SaveChanges();
                return(Ok("Conta adicionada com sucesso."));
            }
            else
            {
                return(BadRequest(conta.Errors()));
            }
        }
Example #3
0
 public void Commit()
 {
     _context.SaveChanges();
 }
Example #4
0
 public void Add(Conta item)
 {
     _context.Contas.Add(item);
     _context.SaveChanges();
 }
Example #5
0
 public void Save()
 {
     _context.SaveChanges();
 }
Example #6
0
 public int SaveChanges()
 {
     return(Db.SaveChanges());
 }