Esempio n. 1
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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates new game.
        /// </summary>
        private void CreateNewGameExecute()
        {
            GameViewModel viewModel = new GameViewModel(new Game(), this.repository);

            this.ShowGame(viewModel);
        }
Esempio n. 3
0
        /// <summary>
        /// On game added.
        /// </summary>
        /// <param name="sender">A Button click.</param>
        /// <param name="e">The click of the button.</param>
        private void OnGameAdded(object sender, GameEventArgs e)
        {
            GameViewModel viewModel = new GameViewModel(e.Game, this.repository);

            this.AllGames.Add(viewModel);
        }