I have a shopping cart stored in session which decreases quantities of items stored in database when user clicks purchase.
If the user closes their browser before they have paid I want to return these quantities back into the database.
I am doing this in the void Session_End(object sender, EventArgs e) event in global.asax but the item quantities are not increasing. I set the session timeout to 1 minute in the web.config and the session is indeed ending because if i sit there with a full shopping cart, it is empty after a minute but the quantities in the database are not updated.
this is my code in session_end
void Session_End(object sender, EventArgs e)
{
if (ShoppingCart.Instance.Items.Count == 0)
return;
foreach (var cartItem in ShoppingCart.Instance.Items.OfType<CartItemGeneric>())
{
var stock = thisModel.EshopItems.Where(i => i.Id == cartItem.Item.Id).First();
stock.SapQuantity += cartItem.Quantity;
thisModel.SaveChanges();
}
}