Click here to Skip to main content
15,885,078 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
int id = Convert.ToInt32(SelectedProduct.ProductId);
foreach (CartProduct item in currentItems)
{

    if (item.ProductId == id)
    {
        item.Quantity += Convert.ToInt32(adet);
        Response.Redirect(Request.RawUrl);
        break;
    }
    else
    {
        ProductFill();
    }
}


The first time he writes on the product.
separately, the product adds the second time.
Please help!
Posted
Comments
dan!sh 27-Mar-11 12:05pm    
Your question isn't clear enough. Could you try and describe it again?
Sandeep Mewara 27-Mar-11 12:09pm    
Not clear. What are you trying to do here and what is the issue?

Use 'Improve Question' link and re-phrase the question.

1 solution

Don't understand you clearly but see you have some problems with adding order line to shopping cart. I would implement it as follows:

public class Order
    {
        public int Amount { get; set; }
        public Guid ProductId { get; set; }
    }

public class ShoppingCart
    {
        public List<order> Orders { get; set; }
        public void Add(Order order)
        {
            if (order == null) return;
            if (Orders.Where(p => p.ProductId == order.ProductId).Count() > 0)
            {
                var existedOrder = Orders.Single(o => o.ProductId == order.ProductId);
                existedOrder.Amount += order.Amount;
            }
            else
            {
                Orders.Add(order);
            }
        }
    }</order>


Also I advice you to separate your bussiness domain logic from UI. It means the method for adding products should not contain some actions for UI just bussiness logic.
 
Share this answer
 
v3

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