Click here to Skip to main content
15,895,772 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hello all ,

I am working on add to cart module .I have one product that have only one Product Quantity, and that product have quantity 1 so two person can not buy that product. at the time of AddToCart I have reduced the quantity from the database.

I have a question:

how to do manage same product for multiple user at same time ?
please suggest me how to do this .
Posted

1 solution

You need to use TRANSACTION in the query which inserts the order details in the database.

While adding to the cart, you cannot determine whether any other user has added it or not, if the time is same. While placing the order, your query will allow only one transaction and after the completion of that it will process another request.

So, when both request will hit the database, one will go through first. Then when second goes, you should have a check inside the query to see if there is any quantity left for the product or not. If there is any left, then allow insert, otherwise not and show message to user that the product is not available at this moment.
 
Share this answer
 
Comments
manvendra patel 17-Jul-15 5:39am    
thanks sir,you explain very well.
Most welcome buddy. :) You explained the question very well too. Giving you 5 stars now.

Keep coding. :)

Regards,
Tadit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900