Example #1
0
        /// <summary>
        /// Event handler for the 'Add transaction' button
        /// </summary>
        /// <remarks>
        /// Fills a transaction and inserts it in the database </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ButtonAddTransaction_Click(object sender, RoutedEventArgs e)
        {
            if (!Utils.IsValid(TransactionGrid))
            {
                MessageBox.Show("Transaction is not valid");
                return;
            }

            // Get selected account
            Account selectedAccount;

            using (var repo = new AccountRepo())
            {
                selectedAccount = repo.GetAccountByConcept((String)AccountComboBox.SelectedItem);
            }

            // Creates transaction
            // TODO: this should use the Transaction created in the constructor
            Transaction transaction = new EF.Transaction()
            {
                Date = DatePicker.DisplayDate, Value = Convert.ToDecimal(textValue.Text), Concept = textConcept.Text, Account = selectedAccount
            };

            using (var repo = new TransactionRepo())
            {
                repo.Add(transaction);
            }

            this.Close();
        }
Example #2
0
        public ActionResult TransactionSuccessful(string trxref, string reference)
        {
            Transaction Transaction      = new Transaction();
            string      UserId           = LoggedInUser.Id.ToString();
            List <Cart> CartTransactions = CartRepo.GetAll(x => x.CustomerId == UserId).ToList();

            foreach (var item in CartTransactions)
            {
                TransactionRepo.Add(new Transaction()
                {
                    AuctioneeId       = UserId,
                    BatchId           = item.Auction.BatchId,
                    BulkPurchase      = false,
                    DateOfTransaction = DateTime.Now,
                    Quantity          = item.Quantity,
                    TransactionType   = TransactionType.Auction,
                    TotalCost         = item.Auction.AuctionPrice * item.Quantity,
                });

                Batch batch = BatchRepo.Get(x => x.Id == item.Auction.BatchId);
                batch.QuantityAuctioned += item.Quantity;
                BatchRepo.Update(batch);
            }

            Guid[] ids = CartTransactions.Select(x => x.Id).ToArray();

            foreach (var item in ids)
            {
                CartRepo.Delete(item);
            }



            return(View());
        }