Create a private method like this.
private List<MYCart> sessionOfCarts
{
get
{
if (Session["sessionOfCarts"] == null)
this.sessionOfCarts = new List<MYCart>();
return (List<MYCart>)Session["sessionOfCarts"];
}
set
{
Session["sessionOfCarts"] = value;
}
}
//Main Method...
public void AddMyCart(MYCart selectedItem)
{
if(sessionOfCarts.Any(p =>p.cartId == selectedItem.cartId))
{
var sample = sessionOfCarts.Select(p =>{
if (p.cartId == selectedItem.cartId)
{ p.Quantity = p.Quantity + 1; }; return p; }).ToList();
}
else
{
sessionOfCarts.Add(selectedItem);
}
}
You can get the selected carts from sessionOfCarts..
Clear that Session once you complete this process..