Quantity minus UnitsInStock
Hi
I have a table in my DB called Products.
Products has various columns but in particular one named ProductId and one named UnitsInStock.
ProductId starts at 1 and increments by 1 and I have a total of 2000 products.
UnitInStock holds the amount of stock for each product ie 5000, 6000 and so on.
I have a SubmitOrder method which persists the data from the ShoppingCart back to the DB in particular the Quantity.
What I would like to do is implement a solution in order to minus the Quantity from the UnitsInStock to enable me to display this on each of the product details.
What I was thinking was to get the UnitsInStock for each ProductId from the Products table and then get the Quantity placed from the Order Details table then subtract one from the other to get a total.
My approach is to get the ProductId and Quanity from the SubmitOrder method ie
OrderDetail od = new OrderDetail();
var getProductId = od.ProductId;
var getQuantity = od.Quantity;
Then somehow call on the Products table getting the UnitsInStock for the particular ProductId passed in and then subtract the Quantity from the UnitsInStock.
Im guessing some sort of Query will be required but im stuck on how to write this.
Thanks
Steven