Exemplo n.º 1
0
        async Task AddContentToCart(Sku item)
        {
            try
            {
                UserDialogService.ShowLoading("正在添加商品");
                var result = await PosSDK.CallAPI <Cart>("/cart/add-item", new
                {
                    cartId   = currentCart.Id,
                    skuId    = item.Id,
                    quantity = 1
                });

                CurrentCart = result.Result;
                RaisePropertyChanged(() => CurrentCart);
                RaisePropertyChanged(() => SubTotalAndQty);
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                UserDialogService.HideLoading();
            }
        }
Exemplo n.º 2
0
        public CartViewModel()
        {
            MessagingCenter.Subscribe <Cart>(this, "SendCart", (c) => {
                CurrentCart = c;
                CartItems   = new ObservableRangeCollection <CartItem>(c.Items);
            });
            MessagingCenter.Subscribe <CartItem>(this, "DeletecartItem", async(i) => {
                ApiResult <Cart> cartResult = await PosSDK.CallAPI <Cart>("/cart/remove-item", new
                {
                    cartId   = i.Id,
                    skuId    = i.Sku.Id,
                    quantity = i.Quantity
                });
                if (cartResult.Success == true)
                {
                    CurrentCart = cartResult.Result;
                    MessagingCenter.Send <Cart>(CurrentCart, "ChangeCart");
                }
            });

            Messenger.Default.Register <string>(this, "OrderPayComplete", m =>
            {
                CurrentCart  = null;
                CartItems    = null;
                SelectedItem = null;
            });
        }
Exemplo n.º 3
0
        async Task ExecuteLoadItemsCommand()
        {
            try
            {
                UserDialogService.ShowLoading("查询中");
                Contents.Clear();
                var result = await PosSDK.CallAPI <ListResult <Sku> >("/catalog/search-skus", new
                {
                    q = SearchText
                });

                Contents.ReplaceRange(result.Result.Items);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                UserDialogService.HideLoading();
            }
        }
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Contents.Clear();
                var result = await PosSDK.CallAPI <ListResult <Content> >("/catalog/search-contents");

                Contents.ReplaceRange(result.Result.Items);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 5
0
        async Task Load(long contentId)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var result = await PosSDK.CallAPI <Content>("/catalog/get-content", new { id = contentId });

                //Skus = new ObservableRangeCollection<Sku>(result.Result.Skus);
                Skus.ReplaceRange(result.Result.Skus);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 6
0
 public PayPrepareViewModel(IUserDialogService dialogService)
 {
     //CurrentCart = cart;
     MessagingCenter.Subscribe <Cart>(this, "PaymentStart", async(s) =>
     {
         CurrentCart = s;
         if (RemainAmt == 0)
         {
             dialogService.ShowLoading("保存销售中");
             try
             {
                 var result = await PosSDK.CallAPI <Cart>("/order/place-order", new
                 {
                     cartId = this.CartId
                 });
                 if (result.Success == true)
                 {
                     Messenger.Default.Send <string>(string.Empty, "OrderPayComplete");
                 }
             }
             catch (Exception)
             {
             }
             finally {
                 dialogService.HideLoading();
             }
         }
     });
 }
Exemplo n.º 7
0
        async Task RemoveContentFromCart(Sku item)
        {
            var result = await PosSDK.CallAPI <Cart>("/cart/remove-item", new
            {
                cartId   = currentCart.Id,
                skuId    = item.Id,
                quantity = 1
            });

            CurrentCart = result.Result;
        }
        async Task CreateNewCart(Sku item)
        {
            var result = await PosSDK.CallAPI <Cart>("/cart/create-cart");

            currentCart = result.Result;

            await AddContentToCart(item);

            currentCart = result.Result;
            MessagingCenter.Send <Cart>(currentCart, "NewCart");
        }
        async Task RemoveContentFromCart(Sku item)
        {
            var result = await PosSDK.CallAPI <Cart>("/cart/remove-item", new
            {
                cartId   = currentCart.Id,
                skuId    = item.Id,
                quantity = 1
            });

            currentCart = result.Result;
            MessagingCenter.Send <Cart>(currentCart, "NewCart");
        }
Exemplo n.º 10
0
        async Task CreateHandCardPay()
        {
            var result = await PosSDK.CallAPI <Cart>("/cart/set-payment", new
            {
                cartId = CartId,
                method = "HandCard",
                amount = ReceivedAmt,
            });

            if (result.Success == true)
            {
                MessagingCenter.Send <Cart>(result.Result, "PaymentStart");
                MessagingCenter.Send <object>(null, "HandCardPayComplete");
            }
        }
Exemplo n.º 11
0
        public async Task <bool> TryLoginAsync()
        {
            var result = await PosSDK.CallAPI <Models.Account>("/account/login", new
            {
                tenant   = "ELAND",
                username = "******",
                password = "******"
            });

            if (result.Success == true)
            {
                Settings.UserId    = result.Result.UserId.ToString();
                Settings.AuthToken = result.Result.Token;
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
        public async Task <bool> TryLoginAsync()
        {
            var result = await PosSDK.CallAPI <Models.Account>("/account/login", new
            {
                tenant   = this.Tenant,
                username = this.Username,
                password = this.Password,
            });

            if (result.Success == true)
            {
                Settings.UserId    = result.Result.UserId.ToString();
                Settings.AuthToken = result.Result.Token;
                App.GoToMainPage();
                return(true);
            }
            return(false);
        }
Exemplo n.º 13
0
 public PayPrepareViewModel()
 {
     //CurrentCart = cart;
     MessagingCenter.Subscribe <Cart>(this, "PaymentStart", async(s) =>
     {
         CurrentCart = s;
         if (RemainAmt == 0)
         {
             var result = await PosSDK.CallAPI <Cart>("/order/place-order", new
             {
                 cartId = this.CartId
             });
             if (result.Success == true)
             {
                 Messenger.Default.Send <string>(string.Empty, "OrderPayComplete");
             }
         }
     });
 }
Exemplo n.º 14
0
        async Task CreateNewCart(Sku item)
        {
            try
            {
                UserDialogService.ShowLoading("生成购物车");

                var result = await PosSDK.CallAPI <Cart>("/cart/create-cart");

                CurrentCart = result.Result;
                MessagingCenter.Send <Cart>(currentCart, "NewCart");
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                UserDialogService.HideLoading();
            }
        }