public void GetTransactionTest()
        {
            var actualResult = new TransactionOrder
            {
                TransactionType = "Sales",
                DateTransaction = DateTime.Now,
                RefNo           = "TestRef"
            };

            actualResult = TransactionOrder.CreateTransaction(actualResult);

            var expectedResult = TransactionOrder.GetTransaction(actualResult.Id);

            UnitTestingHelper.AssertPublicPropertiesEqual(actualResult, expectedResult);

            if (TransactionOrder.GetTransaction("DoesNotExist") != null)
            {
                Assert.Fail("Transaction Order should not exist and must return null");
            }

            if (TransactionOrder.GetTransaction(actualResult.Id + " ") != null)
            {
                Assert.Fail("Transaction Order must return null since the id is modified");
            }

            TransactionOrder.DeleteTransaction(actualResult.Id);
        }
        public void CreateTransactionTest()
        {
            var actualResult = new TransactionOrder
            {
                TransactionType = "Sales",
                DateTransaction = DateTime.Now,
                RefNo           = "TestRef"
            };

            actualResult = TransactionOrder.CreateTransaction(actualResult);
            var expectedResult = TransactionOrder.GetTransaction(actualResult.Id);

            UnitTestingHelper.AssertPublicPropertiesEqual(actualResult, expectedResult);
            TransactionOrder.DeleteTransaction(actualResult.Id);
        }
        public void DeleteTransactionTest()
        {
            var actualResult = new TransactionOrder
            {
                TransactionType = "Sales",
                DateTransaction = DateTime.Now,
                RefNo           = "TestRef"
            };

            actualResult = TransactionOrder.CreateTransaction(actualResult);

            TransactionOrder.DeleteTransaction(actualResult.Id);

            var expectedResult = TransactionOrder.GetTransaction(actualResult.Id);

            Assert.IsNull(expectedResult);
        }
        public void DeleteAllTransactionTest()
        {
            for (var i = 0; i < 5; i++)
            {
                var actualResult = new TransactionOrder
                {
                    TransactionType = "Sales",
                    DateTransaction = DateTime.Now,
                    RefNo           = "TestRef"
                };
                TransactionOrder.CreateTransaction(actualResult);
            }

            var trans          = TransactionOrder.GetAllTransactions();
            var expectedResult = TransactionOrder.DeleteAllTransactions();

            Assert.AreEqual(expectedResult, trans.Count);
        }
        public void EditTransactionTest()
        {
            var actualResult = new TransactionOrder
            {
                TransactionType = "Sales",
                DateTransaction = DateTime.Now,
                RefNo           = "TestRef"
            };

            actualResult       = TransactionOrder.CreateTransaction(actualResult);
            actualResult.RefNo = "Change Ref No";
            TransactionOrder.EditTransaction(actualResult);
            var expectedResult = TransactionOrder.GetTransaction(actualResult.Id);

            Assert.AreEqual(actualResult.RefNo, expectedResult.RefNo);

            TransactionOrder.DeleteTransaction(actualResult.Id);
        }
        /// <summary>
        /// The submit create click event will finalize the transaction and store it in database
        /// </summary>
        /// <param name="sender">
        /// The sender is the parent object of the button, which is the Grid
        /// </param>
        /// <param name="e">
        /// The event argument which contains the product that has been updated or will be updated
        /// </param>
        private void SubmitClick(object sender, RoutedEventArgs e)
        {
            decimal discount, terms;
            string  discountTemp = this.DiscountInput.Text.Replace("%", string.Empty);

            if (!string.IsNullOrWhiteSpace(this.RefIdInput.Text) && !string.IsNullOrWhiteSpace(this.ParticularInput.Text) && !string.IsNullOrWhiteSpace(this.SalesmanInput.Text) && !string.IsNullOrWhiteSpace(this.AddressInput.Text) && decimal.TryParse(discountTemp.Trim(), out discount) && decimal.TryParse(this.TermsInput.Text.Trim(), out terms))
            {
                var order = new TransactionOrder
                {
                    TransactionType    = this.transType,
                    DateTransaction    = DateTime.Now,
                    RefNo              = this.RefIdInput.Text,
                    Particular         = this.ParticularInput.Text,
                    Transactions       = this.transList,
                    DiscountPercentage = discount,
                    ParticularAddress  = this.ParticularInput.Text,
                    SalesmanName       = this.SalesmanInput.Text,
                    Terms              = terms
                };
                TransactionOrder.CreateTransaction(order);
                foreach (var trans in this.transList)
                {
                    var prod = trans.Product;
                    prod = Product.BalanceCasePackPiece(trans, prod, this.transType);
                    Product.EditProduct(prod);
                }

                foreach (Window window in Application.Current.Windows)
                {
                    if (window.Title == "Main")
                    {
                        ((MainMetro)window).InitializeTransView();
                        ((MainMetro)window).InitializeProductsView();
                    }
                }

                this.Close();
            }
            else
            {
                string errorMessage = string.Empty;
                if (string.IsNullOrWhiteSpace(this.RefIdInput.Text))
                {
                    errorMessage = "No value was given in Ref No. Input";
                }
                else if (string.IsNullOrWhiteSpace(this.ParticularInput.Text))
                {
                    errorMessage = "No value was given in Particular Input";
                }
                else if (string.IsNullOrWhiteSpace(this.SalesmanInput.Text))
                {
                    errorMessage = "No value was given in Salesman Input";
                }
                else if (string.IsNullOrWhiteSpace(this.AddressInput.Text))
                {
                    errorMessage = "No value was given in Address Input";
                }
                else if (!decimal.TryParse(discountTemp.Trim(), out discount))
                {
                    errorMessage = "Discount Input has invalid characters or no value was given";
                }
                else if (!decimal.TryParse(this.TermsInput.Text.Trim(), out terms))
                {
                    errorMessage = "Terms Input has invalid characters or no value was given";
                }

                MessageBox.Show(
                    "Error: " + errorMessage,
                    "Error in Creating Transaction Order",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }