Exemple #1
0
 /// <summary>
 /// 新增订单(添加商品到购物车)
 /// </summary>
 /// <param name="good"></param>
 /// <returns></returns>
 public async Task <Order> AddOrderAsync(GoodRequest good)
 {
     try
     {
         return(await _orderStore.AddOrder(new Order
         {
             Price = good.Price,
             UserId = good.UserId,
             OrderId = Guid.NewGuid().ToString(),
             GoodId = good.GoodId,
             GoodNumber = good.GoodNumber,
             Name = good.Name,
             OrderState = 1
         }));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public async Task <IActionResult> AddShopcar(GoodRequest order)
        {
            string userName = HttpContext.Session.GetString("UserName");
            int?   userId   = HttpContext.Session.GetInt32("UserId");

            log.InfoFormat(userName + " || Get into 添加购物车商品");
            try
            {
                order.UserId = userId;
                var or = await _orderManager.AddOrderAsync(order);

                var good = await _indexManager.GetAsync(order.GoodId);

                log.InfoFormat("获取商品详情成功" + (good != null ? Helper.JsonHelper.ToJson(good) : ""));
                log.InfoFormat("添加购物车商品成功" + (or != null ? Helper.JsonHelper.ToJson(or) : ""));
                ViewData["UserName"] = userName;
                return(View("../Index/Goodlistbranchdetails", good));
            }
            catch (Exception e)
            {
                log.Error("添加购物车商品失败,错误提示: " + Helper.JsonHelper.ToJson(e));
                return(View("Error", e));
            }
        }