我的购物车有问题吗? [英] My Shopping Cart Problem?

查看:73
本文介绍了我的购物车有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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!

推荐答案

不清楚,但您发现在向购物车添加订单行时遇到了一些问题.我将实现如下:

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>



我也建议您将您的业务领域逻辑与UI分开.这意味着添加产品的方法不应仅针对业务逻辑来包含针对UI的某些操作.



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.


这篇关于我的购物车有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆