public bool BuyProduct(UserDTO user, int productId, int amount) { ProductDTO foundProduct = productDAO.GetProduct(productId); if (foundProduct.stock < amount) { return(false); } if (user.saldo < foundProduct.price * amount) { return(false); } // Update stock foundProduct.stock -= amount; productDAO.UpdateProduct(foundProduct); // Update user saldo and add product to inventory user.saldo -= foundProduct.price * amount; // Update user saldo userDAO.UpdateUser(user); // Add new row to user inventory userDAO.AddInventoryItem(user, new InventoryDTO { product = foundProduct, amount = amount }); return(true); }