/// <summary>
        /// On receipt added.
        /// </summary>
        /// <param name="sender">A Button click.</param>
        /// <param name="e">The click of the button.</param>
        private void OnReceiptAdded(object sender, ReceiptEventArgs e)
        {
            ReceiptViewModel viewModel = new ReceiptViewModel(e.Receipt, this.repository);

            viewModel.PropertyChanged += this.OnReceiptViewModelPropertyChanged;
            this.AllReceipts.Add(viewModel);
        }
        /// <summary>
        /// Shows all the receipt within the view model.
        /// </summary>
        private void ShowOneReceipt()
        {
            ReceiptViewModel viewModel = this.AllReceipts.SingleOrDefault(vm => vm.IsSelected);

            if (viewModel != null)
            {
                this.ShowReceipt(viewModel);
                this.repository.SaveToDatabase();
            }
            else
            {
                MessageBox.Show("Please select a receipt.");
            }
        }
Exemple #3
0
        /// <summary>
        /// Shows the item in the view.
        /// </summary>
        /// <param name="viewModel">The view model to show.</param>
        private void ShowReceipt(ReceiptViewModel viewModel)
        {
            WorkspaceWindow window = new WorkspaceWindow();

            window.Width  = 400;
            window.Height = 300;
            window.Title  = viewModel.DisplayName;

            viewModel.CloseAction = b => window.DialogResult = b;

            ReceiptView view = new ReceiptView();

            view.DataContext = viewModel;

            window.Content = view;
            window.ShowDialog();
        }
Exemple #4
0
        /// <summary>
        /// A method to sell games within the view model.
        /// </summary>
        private void SellGame()
        {
            GameViewModel viewModel = this.AllGames.SingleOrDefault(vm => vm.IsSelected);

            if (viewModel != null)
            {
                MessageBoxResult result = MessageBox.Show("Are you sure you want to sell this game?", "Purchase confirmation", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    Receipt receipt = new Receipt
                    {
                        AccountId         = this.account.Id,
                        GameId            = viewModel.Game.Id,
                        DateIssued        = DateTime.Now.ToShortDateString(),
                        TransactionAmount = viewModel.SellPrice,
                        InvoiceNumber     = Guid.NewGuid().ToString(),
                        PaymentMethod     = "Account Funds Added To Account"
                    };

                    this.repository.AddReceipt(receipt);

                    this.account.AccountFunds += viewModel.SellPrice;
                    this.account.Library.Remove(viewModel.Game);
                    this.UserGames.Remove(viewModel);

                    List <GameViewModel> games = this.GetAllGames();

                    foreach (GameViewModel g in games)
                    {
                        if (viewModel.Name == g.Name)
                        {
                            viewModel.UsedQuantity++;
                            this.repository.SaveToDatabase();
                        }
                    }

                    this.UpdateViews();

                    ReceiptViewModel receiptViewModel = new ReceiptViewModel(receipt, this.repository);
                    this.ShowReceipt(receiptViewModel);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Purchase a game.
        /// </summary>
        /// <param name="quality">The quality of the game.</param>
        private void BuyGame(string quality)
        {
            GameViewModel viewModel = this.AllGames.SingleOrDefault(vm => vm.IsSelected);

            if (viewModel != null)
            {
                switch (quality)
                {
                case "New":
                    if (this.account.AccountFunds > viewModel.Price)
                    {
                        MessageBoxResult result = MessageBox.Show("Are you sure you want to buy this game?", "Purchase confirmation", MessageBoxButton.YesNo);

                        if (result == MessageBoxResult.Yes)
                        {
                            if (this.account.Library.Contains(viewModel.Game))
                            {
                                MessageBox.Show("You already own this game!");
                                break;
                            }

                            this.account.AccountFunds -= viewModel.Price;
                            this.account.Library.Add(viewModel.Game);
                            this.UserGames.Add(viewModel);
                            Receipt receipt = new Receipt
                            {
                                AccountId         = this.account.Id,
                                GameId            = viewModel.Game.Id,
                                DateIssued        = DateTime.Now.ToShortDateString(),
                                TransactionAmount = viewModel.Game.Price,
                                InvoiceNumber     = Guid.NewGuid().ToString(),
                                PaymentMethod     = "VISA"
                            };

                            this.repository.AddReceipt(receipt);

                            ReceiptViewModel receiptViewModel = new ReceiptViewModel(receipt, this.repository);
                            this.ShowReceipt(receiptViewModel);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Account funds unavailable.");
                    }

                    break;

                case "Used":
                    if (this.account.AccountFunds > viewModel.UsedPrice && viewModel.UsedQuantity > 0)
                    {
                        MessageBoxResult result = MessageBox.Show("Are you sure you want to buy this game?", "Purchase confirmation", MessageBoxButton.YesNo);

                        if (result == MessageBoxResult.Yes)
                        {
                            if (this.account.Library.Contains(viewModel.Game))
                            {
                                MessageBox.Show("You already own this game!");
                                break;
                            }

                            this.account.AccountFunds -= viewModel.UsedPrice;
                            this.account.Library.Add(viewModel.Game);
                            this.UserGames.Add(viewModel);
                            viewModel.UsedQuantity--;

                            Receipt receipt = new Receipt
                            {
                                AccountId         = this.account.Id,
                                GameId            = viewModel.Game.Id,
                                DateIssued        = DateTime.Now.ToShortDateString(),
                                TransactionAmount = viewModel.Game.UsedPrice,
                                InvoiceNumber     = Guid.NewGuid().ToString(),
                                PaymentMethod     = "VISA"
                            };

                            this.repository.AddReceipt(receipt);

                            ReceiptViewModel receiptViewModel = new ReceiptViewModel(receipt, this.repository);
                            this.ShowReceipt(receiptViewModel);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Account funds unavailable.");
                    }

                    break;
                }

                this.repository.SaveToDatabase();
                this.UpdateViews();
            }
        }