Example #1
0
        /// <summary>
        /// Method to delete a single item from the database
        /// </summary>
        /// <param name="id">id of the item marked for deletion</param>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            var dbContext    = new TransactionsContext();
            var itemToRemove = dbContext.testts.SingleOrDefault(x => x.Id == id);

            if (itemToRemove != null)
            {
                dbContext.testts.Remove(itemToRemove);
                dbContext.SaveChanges();
            }

            return(RedirectToAction("ViewDbData"));
        }
Example #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();
                 }
             }
         }
     }
 }