Ejemplo n.º 1
0
        public long InsertBillingInfo(BillingInfo billingInfo)
        {
            try
            {
                Database db = DatabaseFactory.CreateDatabase("DbConnection");

                int currentDate = 0;
                int currentTime = 0;
                Common.GetCurrentDateTime(out currentDate, out currentTime);

                using (DbConnection connection = db.CreateConnection())
                {
                    DbTransaction transaction = null;
                    try
                    {
                        connection.Open();
                        transaction = connection.BeginTransaction();

                        long billingID = BillingDAL.InsertBilling(db, transaction, billingInfo.Comments, billingInfo.TotalPrice, billingInfo.UserID, currentDate, currentTime);

                        foreach (BillingItemInfo itemInfo in billingInfo.BillingItemList)
                        {
                            BillingDAL.InsertBillingItem(db, transaction, billingID, itemInfo.ItemID, itemInfo.ItemPrice, itemInfo.Quantity);
                        }

                        transaction.Commit();
                        return(billingID);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        if (connection != null && connection.State != ConnectionState.Closed)
                        {
                            connection.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
                throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError);
            }
        }