Пример #1
0
 internal TResult Perform <TResult>(
     IPerformableAction <TResult> action,
     bool transactional = true)
 {
     if (transactional)
     {
         using (IBillingContext context = BillingContext.Create())
         {
             using (var transaction = TransactionUtils.CreateTransaction())
             {
                 action.DbContext = context;
                 TResult result = action.Perform();
                 transaction.Complete();
                 return(result);
             }
         }
     }
     else
     {
         using (IBillingContext context = BillingContext.Create())
         {
             action.DbContext = context;
             return(action.Perform());
         }
     }
 }
Пример #2
0
        public bool Create(User user)
        {
            BillingContext bc    = new BillingContext(new MSSQLBillingContext());
            bool           state = false;
            string         query = $"INSERT INTO dbo.User INSERT INTO (email, password,billingID) VALUES (@email,@password,@billingID)";

            try
            {
                if (OpenConnection())
                {
                    using (SqlCommand cmd = new SqlCommand(query, Connection))
                    {
                        try
                        {
                            cmd.Parameters.AddWithValue("@email", user.Email);
                            cmd.Parameters.AddWithValue("@password", user.Password);
                            cmd.Parameters.AddWithValue("@billingID", bc.Create(user.Billing));
                            cmd.ExecuteNonQuery();
                            state = true;
                        }
                        catch (SqlException e)
                        {
                            throw e;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(state);
        }
Пример #3
0
 internal void  Perform(
     IPerformableAction action,
     bool transactional = true)
 {
     if (transactional)
     {
         using (IBillingContext context = BillingContext.Create())
         {
             using (var transaction = TransactionUtils.CreateTransaction())
             {
                 action.DbContext = context;
                 action.Perform();
                 transaction.Complete();
             }
         }
     }
     else
     {
         using (IBillingContext context = BillingContext.Create())
         {
             action.DbContext = context;
             action.Perform();
         }
     }
 }