Ejemplo n.º 1
0
        Boolean IProductService.BuyProduct(string productName, string username)
        {
            Product product = persistenceService.FindProductByID(productName);

            if (product == null)
            {
                return(false);
            }

            User user = persistenceService.FindUserByID(username);

            if (user == null)
            {
                return(false);
            }
            if (product.Price > user.Money)
            {
                return(false);
            }

            product.AmountInStock = product.AmountInStock - 1;
            if (product.AmountInStock <= 0)
            {
                persistenceService.DeleteProduct(product.Name);
            }
            else
            {
                persistenceService.InsertOrUpdateProduct(product);
            }


            user.Money = user.Money - product.Price;
            persistenceService.InsertOrUpdateUser(user);
            //TODO: add to user inv items

            return(true);
        }