protected DataSet GetData()
        {
            List <TransactionHeader> headers = TransactionHeaderRepository.GetAllTransactions();
            DataSet ds        = new DataSet();
            var     ds_header = ds.TransactionHeader;
            var     ds_detail = ds.TransactionDetail;

            foreach (var header in headers)
            {
                var newRow = ds_header.NewRow();
                newRow["Id"]     = header.Id;
                newRow["UserId"] = header.UserId;
                newRow["Date"]   = header.TransactionDate;
                ds_header.Rows.Add(newRow);

                List <TransactionDetail> details = TransactionDetailRepository.GetTransactionDetails(header.Id);

                foreach (var detail in details)
                {
                    var newRowDetail = ds_detail.NewRow();
                    newRowDetail["TransactionId"] = detail.TransactionId;
                    newRowDetail["ProductId"]     = detail.ProductId;
                    newRowDetail["ProductName"]   = ProductRepository.GetProductById(detail.ProductId).Name;
                    newRowDetail["Price"]         = ProductRepository.GetProductById(detail.ProductId).Price;
                    newRowDetail["Quantity"]      = ProductRepository.GetProductById(detail.ProductId).Quantity;
                    ds_detail.Rows.Add(newRowDetail);
                }
            }

            return(ds);
        }
Beispiel #2
0
        public void GetByIdTest()
        {
            var transactionrepo = new TransactionDetailRepository(transactioncontextmock.Object);
            var transactionlist = transactionrepo.GetById(11);

            Assert.AreEqual(1, transactionlist.Count());
        }
        public static bool Checkout(int userId)
        {
            List <Cart> carts = GetThisUserCart(userId);

            if (carts.Count == 0)
            {
                return(false);
            }
            else
            {
                TransactionHeader transactionHeader = TransactionHeaderFactory.Create(userId);

                if (TransactionHeaderRepository.InsertTransactionHeader(transactionHeader))
                {
                    int headerId = transactionHeader.Id;

                    for (int i = 0; i < carts.Count(); i++)
                    {
                        TransactionDetail transactionDetail = TransactionDetailFactory.Create(headerId, carts[i].ProductId, carts[i].Quantity);
                        TransactionDetailRepository.InsertTransactionDetail(transactionDetail);
                    }

                    for (int i = 0; i < carts.Count(); i++)
                    {
                        CartRepository.RemoveCart(carts[i]);
                    }

                    return(true);
                }

                return(false);
            }
        }
Beispiel #4
0
        public void TransferTest()
        {
            var transactionrepo = new TransactionDetailRepository(transactioncontextmock.Object);
            var transactionobj  = transactionrepo.Transfer(new TransactionDetails {
                TransactionId = 3, UserId = 10, FromAccount = 101, ToAccount = 102, Amount = 5000
            });

            Assert.IsNotNull(transactionobj);
        }
Beispiel #5
0
        private async Task SaveContent()
        {
            var  _transactionDetailRepository = new TransactionDetailRepository();
            bool isUserAccept = await Application.Current.MainPage.DisplayAlert("Verify Cheque Deatils", "Do you want to continue?", "OK", "Cancel");

            if (isUserAccept)
            {
                _transactionDetailRepository.InsertData(ChequeTransaction);
                var page = FindPageByType(typeof(Dashboard));
                var vm   = (DashboardViewModel)page.BindingContext;
                //vm.Item.Insert(0, saveContent);
                await App.navigationPage.PopAsync();
            }
        }
Beispiel #6
0
        public void Create_ShouldSaveTransactionAndDetailsWhenInvoked()
        {
            var totalQuantity    = 10;
            var purchaseQuantity = 5;
            var price            = 4.99;

            var options = new DbContextOptionsBuilder <ApiContext>()
                          .UseInMemoryDatabase(databaseName: "Create_ShouldSaveTransactionAndDetailsWhenInvoked")
                          .Options;

            using (var context = new ApiContext(options))
            {
                // initialize objects
                var itemRepository = new ItemRepository(context);
                var transactionDetailRepository = new TransactionDetailRepository(context);
                var transactionRepository       = new TransactionRepository(context);
                var userRepository = new UserRepository(context);
                var service        = new TransactionService(itemRepository, transactionDetailRepository, transactionRepository);

                // add data
                var item = new Item
                {
                    Name        = "Item1",
                    Description = "Description1",
                    Price       = price,
                    Quantity    = totalQuantity
                };
                itemRepository.Add(item);
                itemRepository.Commit();
                var user = new User
                {
                    AuthId = "auth|test-user",
                    Email  = "*****@*****.**"
                };
                userRepository.Add(user);
                userRepository.Commit();

                // preform action
                var transaction = service.Create(new List <PurchaseOrderItemDTO>
                {
                    new PurchaseOrderItemDTO {
                        ItemId = item.Id, Quantity = purchaseQuantity
                    }
                }, user.Id);
            }

            using (var context = new ApiContext(options))
            {
                // initialize objects
                var itemRepository = new ItemRepository(context);
                var transactionDetailRepository = new TransactionDetailRepository(context);
                var transactionRepository       = new TransactionRepository(context);
                var userRepository = new UserRepository(context);
                var service        = new TransactionService(itemRepository, transactionDetailRepository, transactionRepository);


                var transactions = transactionRepository.AllProperties();
                Assert.NotEmpty(transactions);
                Assert.Equal(1, transactions.Count());
                var transaction = transactions.FirstOrDefault();
                Assert.Equal(price * purchaseQuantity, transaction.Total);
                Assert.Equal(1, transaction.Details.Count);
                // Validate that quantity of Item changed in inventory
                Assert.Equal(totalQuantity - purchaseQuantity, transaction.Details.FirstOrDefault().Item.Quantity);
            }
        }