Exemplo n.º 1
0
 public async Task <IHttpActionResult> Put([FromODataUri] int key, Transaction update)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (key != update.Id)
     {
         return(BadRequest());
     }
     db.Entry(update).State = EntityState.Modified;
     try
     {
         await db.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!ProductExists(key))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(Updated(update));
 }
Exemplo n.º 2
0
 public void SalvarTransacoes(List <Transaction> trs)
 {
     foreach (var item in trs)
     {
         using (var ctx = new TransactionsContext())
         {
             using (var ctxTransaction = ctx.Database.BeginTransaction())
             {
                 try
                 {
                     ctx.Entry(item.Account).State = EntityState.Modified;
                     ctx.Transactions.Add(item);
                     ctx.SaveChanges();
                     ctxTransaction.Commit();
                 }
                 catch (Exception)
                 {
                     ctxTransaction.Rollback();
                 }
             }
         }
     }
 }