Ejemplo 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();
            }
        }
Ejemplo 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;
            });
        }
Ejemplo 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;
            }
        }
Ejemplo 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;
            }
        }
Ejemplo 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();
             }
         }
     });
 }
Ejemplo 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;
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
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;
            MessagingCenter.Send <Cart>(currentCart, "NewCart");
        }
Ejemplo 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");
            }
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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");
             }
         }
     });
 }
Ejemplo 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();
            }
        }