示例#1
0
        public int Execute(ShopCartModel shopCartModel)
        {
            var shopCart = _repo.ShopCart.FindByCondition(x => x.Id == shopCartModel.Id).FirstOrDefault();

            if (shopCart == null)
            {
                var newShopCart = new Entities.Models.ShopCart
                {
                    Quantity       = shopCartModel.Quantity,
                    AdditionalInfo = shopCartModel.AdditionalInfo,
                    ProductId      = shopCartModel.ProductId
                };

                _repo.ShopCart.Create(newShopCart);
                _repo.Save();
                return(newShopCart.Id);
            }
            else
            {
                shopCart.Quantity       = shopCartModel.Quantity;
                shopCart.AdditionalInfo = shopCartModel.AdditionalInfo;
                shopCart.ProductId      = shopCartModel.ProductId;


                _repo.ShopCart.Update(shopCart);
                _repo.Save();
                return(shopCart.Id);
            }
        }
        public async Task <IActionResult> OnGetAsync()
        {
            var userName = "******";

            Cart = await _shopCartApi.GetShopCart(userName);

            return(Page());
        }
示例#3
0
        public void Execute(ShopCartModel shopCartModel)
        {
            var shopCartToUpdate = _repo.ShopCart.FindByCondition(x => x.Id == shopCartModel.Id).FirstOrDefault();

            shopCartToUpdate.Quantity       = shopCartModel.Quantity;
            shopCartToUpdate.AdditionalInfo = shopCartModel.AdditionalInfo;
            shopCartToUpdate.ProductId      = shopCartModel.ProductId;


            _repo.ShopCart.Update(shopCartToUpdate);
            _repo.Save();
        }
        public async Task <ShopCartModel> UpdateShopCart(ShopCartModel model)
        {
            var message = new HttpRequestBuilder(_settings.BaseAddress)
                          .SetPath(_settings.ShopCartPath)
                          .HttpMethod(HttpMethod.Post)
                          .GetHttpMessage();

            var json = JsonConvert.SerializeObject(model);

            message.Content = new StringContent(json, Encoding.UTF8, "application/json");

            return(await SendRequest <ShopCartModel>(message));
        }
        public async Task <IActionResult> OnPostCheckOutAsync()
        {
            var userName = "******";

            Cart = await _shopCartApi.GetShopCart(userName);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Order.UserName   = userName;
            Order.TotalPrice = Cart.TotalPrice;

            await _shopCartApi.CheckoutShopCart(Order);

            return(RedirectToPage("Confirmation", "OrderSubmitted"));
        }
示例#6
0
 public void UpdateShopCart(ShopCartModel shopCartModel)
 {
     new UpdateShopCartOperation(_repository).Execute(shopCartModel);
 }
示例#7
0
 public int CreateOrUpdateShopCart(ShopCartModel shopCartModel)
 {
     return(new SaveOrUpdateShopCartOperation(_repository).Execute(shopCartModel));
 }
示例#8
0
 public IActionResult UpdateShopCart([FromBody] ShopCartModel shopCart)
 {
     _service.UpdateShopCart(shopCart);
     return(Ok(shopCart));
 }
示例#9
0
        public IActionResult CreateShopCart([FromBody] ShopCartModel shopCart)
        {
            var id = _service.CreateOrUpdateShopCart(shopCart);

            return(Ok(shopCart));
        }