Пример #1
0
        public GameStoreViewModel(IDispatcherService dispatcherService, string functionTag,
                                  IDialogService dialogService, ScoreInfoService scoreInfoService, GoodsService goodsService) : base(dispatcherService, functionTag)
        {
            _dialogService    = dialogService;
            _scoreInfoService = scoreInfoService;
            _goodsService     = goodsService;

            DataGridItemChanged = new RelayCommand <DataGridItemChangedEventArgs>(OnDataGridItemChanged);

            RefreshList = new RelayCommand(PrivateRefreshList);

            RemoveItem = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除选中数据吗?"))
                {
                    _ = _goodsService.RemoveAsync(SelectedItem);
                    GoodsItems.Remove(SelectedItem);
                }
            }, () => { return(SelectedItem != null); });

            RemoveAll = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除所有数据吗?"))
                {
                    _          = _goodsService.RemoveAllAsync();
                    GoodsItems = null;
                }
            }, () => { return(GoodsItems != null); });

            AddData = new RelayCommand(() =>
            {
                if (string.IsNullOrEmpty(BuyCmd))
                {
                    _dialogService.ShowInformation("购买命令不能为空");
                    return;
                }
                if (GoodsItems.FirstOrDefault(p => p.BuyCmd == BuyCmd) != null)
                {
                    _dialogService.ShowInformation("购买命令重复");
                    return;
                }

                var dto = new GoodsDto()
                {
                    GoodsName = GoodsName,
                    BuyCmd    = BuyCmd,
                    Content   = Content,
                    Amount    = Amount,
                    Quality   = Quality,
                    Price     = Price,
                    GoodsType = GoodsType
                };
                _ = _goodsService.AddAsync(dto);
                GoodsItems.Add(dto);
            });

            AddAvailableVariables();

            PrivateRefreshList();
        }