コード例 #1
0
        public TransactionDM Create(TransactionDM model)
        {
            TransactionDM result;
            int           id;

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    string queryString = DatabaseResources.InsertTransaction;

                    using (SqlCommand command = new SqlCommand(queryString, connection))
                    {
                        command.Parameters.AddWithValue("@Sku", model.Sku);
                        command.Parameters.AddWithValue("@Amount", model.Amount);
                        command.Parameters.AddWithValue("@Currency", model.Currency);
                        id = (int)command.ExecuteScalar();
                    }
                }
                result = ReadById(id);
            }
            #region Exceptions
            catch (InvalidCastException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (IOException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (ObjectDisposedException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (InvalidOperationException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (SqlException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (ArgumentNullException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (FormatException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (OverflowException e)
            {
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            #endregion
            return(result);
        }
コード例 #2
0
        public void SetUp()
        {
            ConfigHelper.CleanDatabase();
            transactionRepository = Resolve <ITransactionRepository>();

            createdTransactionDMList = new List <TransactionDM>();
            transactionDM0           = new TransactionDM("T001", 12.34m, "EUR");
            transactionDM1           = new TransactionDM("T001", 15.23m, "USD");

            sameSkuTransactionDMList = new List <TransactionDM>
            {
                transactionDM0,
                transactionDM1
            };

            transactionDMList = new List <TransactionDM>
            {
                transactionDM0,
                transactionDM1,
                new TransactionDM("T002", 15.54m, "EUR"),
                new TransactionDM("T003", 2.04m, "DOL")
            };
            createdTransactionDMList = transactionRepository.CreateAll(transactionDMList);
        }
コード例 #3
0
        public TransactionDM ReadById(int id)
        {
            TransactionDM result = null;

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    string queryString = DatabaseResources.SelectTransactionById;
                    using (SqlCommand command = new SqlCommand(queryString, connection))
                    {
                        command.Parameters.AddWithValue("@TransactionId", id);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                string  sku      = reader["Sku"].ToString();
                                decimal amount   = Decimal.Parse(reader["Amount"].ToString());
                                string  currency = reader["Currency"].ToString();
                                result = new TransactionDM(sku, amount, currency);
                            }
                        }
                    }
                }
            }
            #region Exceptions
            catch (InvalidCastException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (IOException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (ObjectDisposedException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (InvalidOperationException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (SqlException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (ArgumentNullException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (FormatException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (OverflowException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            #endregion
            return(result);
        }
コード例 #4
0
        public List <TransactionDM> ReadAll()
        {
            List <TransactionDM> result = new List <TransactionDM>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    string queryString = DatabaseResources.SelectTransactions;
                    using (SqlCommand command = new SqlCommand(queryString, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                string        sku      = reader["Sku"].ToString();
                                decimal       amount   = Decimal.Parse(reader["Amount"].ToString());
                                string        currency = reader["Currency"].ToString();
                                TransactionDM model    = new TransactionDM(sku, amount, currency);
                                result.Add(model);
                            }
                        }
                    }
                }
            }
            #region Exceptions
            catch (InvalidCastException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (IOException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (ObjectDisposedException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (InvalidOperationException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (SqlException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (ArgumentNullException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (FormatException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            catch (OverflowException e)
            {
                Log.Error(e.Message);
                Log.Warning(e.StackTrace);
                throw new VuelingExamInfrastructureException(e.Message, e.InnerException);
            }
            #endregion
            return(result);
        }