示例#1
0
 public void MapToBo(SK_WM_ShopCarGoodsItem bo)
 {
     bo.ID                = ID;
     bo.GoodsID           = GoodsID;
     bo.SortCode          = SortCode;
     bo.ShopName          = ShopName;
     bo.GoodsName         = GoodsName;
     bo.Count             = Count;
     bo.Price             = Price;
     bo.TotalPrice        = TotalPrice;
     bo.BelongToShopCarID = BelongToShopCarID;
     bo.ShopCarForUser    = ShopCarForUser;
     bo.ImgPath           = ImgPath;
     bo.CreateOrderTime   = CreateOrderTime;
 }
示例#2
0
 public SK_WM_ShopCarGoodsItemVM(SK_WM_ShopCarGoodsItem bo)
 {
     ID                = bo.ID;
     GoodsID           = bo.GoodsID;
     SortCode          = bo.SortCode;
     ShopName          = bo.ShopName;
     GoodsName         = bo.GoodsName;
     Count             = bo.Count;
     Price             = bo.Price;
     TotalPrice        = bo.TotalPrice;
     BelongToShopCarID = bo.BelongToShopCarID;
     ShopCarForUser    = bo.ShopCarForUser;
     ImgPath           = bo.ImgPath;
     CreateOrderTime   = bo.CreateOrderTime;
 }
示例#3
0
        public async Task <IActionResult> AddToShoppingCar(SK_WM_ShopCarGoodsItem scItem)
        {
            try
            {
                //var status = false;
                var username = User.Identity.Name;
                if (username == null)
                {
                    //return View("../../Views/Home/Logon");
                    Json(new { isOK = false, message = "请登录后再执行操作" });
                }
                var user = await _UserManager.FindByNameAsync(username);

                if (user == null)
                {
                    //return View("../../Views/Home/Logon");
                    Json(new { isOK = false, message = "请登录后再执行操作" });
                }

                var shopcar = await _ShopCarRepository.FindByAsyn(x => x.BelongToUserID == user.Id);

                if (shopcar.Count() == 0)
                {
                    var shopCar = new SK_WM_ShopCar()
                    {
                        BelongToUserID = user.Id,
                        ShopCarForUser = user
                    };
                    await _ShopCarRepository.AddOrEditAndSaveAsyn(shopCar);

                    shopcar = await _ShopCarRepository.FindByAsyn(x => x.BelongToUserID == user.Id);
                }

                var goods = _GoodsRepository.GetSingleBy(x => x.ID == Guid.Parse(scItem.GoodsID));

                var imgs = await _ImageRepository.FindByAsyn(x => x.RelevanceObjectID == goods.ID);

                var img = imgs.Where(x => x.IsForTitle == true).FirstOrDefault();

                var shop = _ShopRepository.GetSingleBy(x => x.ID == Guid.Parse(goods.BelongToShopID));

                //查询该用户的购物车下的所有商品
                var goodsItem = await _ShopCarGoodsItemRepository.FindByAsyn(x => x.BelongToShopCarID == shopcar.FirstOrDefault().ID.ToString());

                //查询该用户购物车内的商品内是否有正要添加的商品
                var hasGoods = goodsItem.Where(x => x.GoodsName == scItem.GoodsName);

                var sItem = new SK_WM_ShopCarGoodsItem();
                if (hasGoods.Count() == 0)//判断原购物车是否有要添加的商品、如果有就在原来的基础上修改数量及总价、否则直接添加新的
                {
                    sItem = new SK_WM_ShopCarGoodsItem()
                    {
                        BelongToShopCarID = shopcar.FirstOrDefault().ID.ToString(),
                        shopCar           = shopcar.FirstOrDefault(),
                        GoodsID           = scItem.GoodsID,
                        Count             = scItem.Count,
                        Price             = scItem.Price,
                        TotalPrice        = (scItem.Count * decimal.Parse(scItem.Price)).ToString(),
                        ShopName          = shop.Name,
                        GoodsName         = goods.Name,
                        ImgPath           = img.UploadPath,
                        CreateOrderTime   = DateTime.Now,
                    };
                    _ShopCarGoodsItemRepository.AddOrEditAndSave(sItem);
                }
                else
                {
                    var hItem = hasGoods.FirstOrDefault();
                    hItem.Count      = scItem.Count + hItem.Count;
                    hItem.TotalPrice = (hItem.Count * decimal.Parse(scItem.Price)).ToString();
                    _ShopCarGoodsItemRepository.AddOrEditAndSave(hItem);
                }


                return(Json(new { isOK = true, message = "添加购物车成功" }));
            }
            catch (Exception)
            {
                return(Json(new { isOK = false, message = "添加失败,请检查登录状态后再执行操作" }));
            }
        }