Ejemplo n.º 1
0
 public Order TransactionPayment(Order order, IEnumerable <OrderDetail> orderDetails, BankCreditCard bankCreditCard)
 {
     try
     {
         using (var bankContext = new BankContext())
         {
             using (var transaction = bankContext.Database.BeginTransaction())
             {
                 try
                 {
                     Order orderAdded;
                     bankContext.Entry(bankCreditCard).State = System.Data.Entity.EntityState.Modified;
                     bankContext.SaveChanges();
                     using (var pOPContext = new POPContext())
                     {
                         orderAdded = pOPContext.Orders.Add(order);
                         pOPContext.SaveChanges();
                         foreach (var item in orderDetails)
                         {
                             item.OrderId = order.OrderId;
                             pOPContext.OrderDetails.Add(item);
                         }
                         pOPContext.OrderDetails.AddRange(orderDetails);
                         //Save and discard changes
                         pOPContext.SaveChanges();
                     }
                     transaction.Commit();
                     return(orderAdded);
                 }
                 catch (Exception)
                 {
                 }
             }
         }
     }
     catch (Exception e)
     {
     }
     return(null);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Inserts a single object to the database and commits the change
 /// </summary>
 /// <remarks>Synchronous</remarks>
 /// <param name="t">The object to insert</param>
 /// <returns>The resulting object including its primary key after the insert</returns>
 public TObject Add(TObject t)
 {
     _context.Set<TObject>().Add(t);
     _context.SaveChanges();
     return t;
 }