Example #1
0
        void HandlePurchase(string username, int productId, int cnt)
        {
            User    user;
            Product product;

            try
            {
                user    = _stregsystem.GetUserByUsername(username);
                product = _stregsystem.GetProductByID(productId);
                for (int i = 0; i < cnt; i++)
                {
                    try
                    {
                        BuyTransaction buyTransaction = _stregsystem.BuyProduct(user, product);
                        _stregsystemUI.DisplayUserBuysProduct(buyTransaction);
                    }
                    catch (InaktivProductPurchaseExceptions)
                    {
                        _stregsystemUI.DisplayProductInactive(productId.ToString());
                        break;
                    }
                    catch (InsufficientCreditsException)
                    {
                        _stregsystemUI.DisplayInsufficientCash(user, product);
                        break;
                    }
                }
            }
            catch (ProductNotFoundException ex)
            {
                _stregsystemUI.DisplayProductNotFound(productId.ToString());
                Debug.WriteLine(ex);
            }
            catch (UserNotFoundException ex)
            {
                _stregsystemUI.DisplayUserNotFound(username);
                Debug.WriteLine(ex);
            }
        }