Esempio n. 1
0
        public RedemptionStoreWindowViewModel()
        {
            foreach (RedemptionStoreProductModel product in ChannelSession.Settings.RedemptionStoreProducts.Values.ToList().OrderBy(p => p.Name))
            {
                this.Products.Add(new RedemptionStoreProductViewModel(this, product));
            }

            this.ChatPurchaseCommand = ChannelSession.Settings.RedemptionStoreChatPurchaseCommand;
            this.ModRedeemCommand    = ChannelSession.Settings.RedemptionStoreModRedeemCommand;

            this.ManualRedeemNeededCommand = ChannelSession.Settings.GetCustomCommand(ChannelSession.Settings.RedemptionStoreManualRedeemNeededCommandID);
            this.DefaultRedemptionCommand  = ChannelSession.Settings.GetCustomCommand(ChannelSession.Settings.RedemptionStoreDefaultRedemptionCommandID);

            this.SaveProductCommand = this.CreateCommand(async(parameter) =>
            {
                if (string.IsNullOrEmpty(this.ProductName))
                {
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.ValidProductName);
                    return;
                }

                RedemptionStoreProductViewModel duplicateProduct = this.Products.FirstOrDefault(p => p.Name.Equals(this.ProductName));
                if (duplicateProduct != null && duplicateProduct.Product != this.SelectedProduct)
                {
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.ProductNameAlreadyExists);
                    return;
                }

                if (!await this.ProductRequirements.Validate())
                {
                    return;
                }

                RedemptionStoreProductModel product = this.SelectedProduct;
                if (this.SelectedProduct == null)
                {
                    product = new RedemptionStoreProductModel();
                }

                product.Name          = this.ProductName;
                product.MaxAmount     = product.CurrentAmount = this.ProductQuantity;
                product.AutoReplenish = this.ProductAutoReplenish;
                product.AutoRedeem    = this.ProductAutoRedeem;
                product.Requirements  = this.ProductRequirements.GetRequirements();

                if (this.SelectedProduct == null)
                {
                    this.Products.Add(new RedemptionStoreProductViewModel(this, product));
                }

                this.SelectedProduct = null;

                this.RefreshProducts();
            });
        }
        public RedemptionStoreWindowViewModel()
        {
            this.Products.AddRange(ChannelSession.Settings.RedemptionStoreProducts.Values.ToList().OrderBy(p => p.Name).Select(p => new RedemptionStoreProductViewModel(this, p)));

            this.ChatPurchaseCommand = ChannelSession.Settings.RedemptionStoreChatPurchaseCommand;
            this.ModRedeemCommand    = ChannelSession.Settings.RedemptionStoreModRedeemCommand;

            this.ManualRedeemNeededCommand = (CustomCommandModel)ChannelSession.Settings.GetCommand(ChannelSession.Settings.RedemptionStoreManualRedeemNeededCommandID);
            this.DefaultRedemptionCommand  = (CustomCommandModel)ChannelSession.Settings.GetCommand(ChannelSession.Settings.RedemptionStoreDefaultRedemptionCommandID);

            this.SaveProductCommand = this.CreateCommand(async() =>
            {
                if (string.IsNullOrEmpty(this.ProductName))
                {
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.ValidProductName);
                    return;
                }

                RedemptionStoreProductViewModel duplicateProduct = this.Products.FirstOrDefault(p => p.Name.Equals(this.ProductName));
                if (duplicateProduct != null && duplicateProduct.Product != this.SelectedProduct)
                {
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.ProductNameAlreadyExists);
                    return;
                }

                IEnumerable <Result> requirementResults = await this.ProductRequirements.Validate();
                if (requirementResults.Any(r => !r.Success))
                {
                    await DialogHelper.ShowMessage(string.Join(Environment.NewLine, requirementResults.Where(r => !r.Success).Select(r => r.Message)));
                }

                RedemptionStoreProductModel product = this.SelectedProduct;
                if (this.SelectedProduct == null)
                {
                    product = new RedemptionStoreProductModel();
                }

                product.Name          = this.ProductName;
                product.MaxAmount     = product.CurrentAmount = this.ProductQuantity;
                product.AutoReplenish = this.ProductAutoReplenish;
                product.AutoRedeem    = this.ProductAutoRedeem;
                product.Requirements  = this.ProductRequirements.GetRequirements();

                if (this.SelectedProduct == null)
                {
                    this.Products.Add(new RedemptionStoreProductViewModel(this, product));
                }

                this.SelectedProduct = null;

                this.RefreshProducts();
            });
        }
Esempio n. 3
0
        public RedemptionStoreProductViewModel(RedemptionStoreWindowViewModel viewModel, RedemptionStoreProductModel product)
        {
            this.viewModel = viewModel;
            this.Product   = product;

            this.EditProductCommand = this.CreateCommand((parameter) =>
            {
                this.viewModel.EditProduct(this);
                return(Task.FromResult(0));
            });

            this.DeleteProductCommand = this.CreateCommand(async(parameter) =>
            {
                await this.viewModel.DeleteProduct(this);
            });
        }
        public RedemptionStoreProductViewModel(RedemptionStoreWindowViewModel viewModel, RedemptionStoreProductModel product)
        {
            this.viewModel = viewModel;
            this.Product   = product;

            this.EditProductCommand = this.CreateCommand(() =>
            {
                this.viewModel.EditProduct(this);
            });

            this.DeleteProductCommand = this.CreateCommand(async() =>
            {
                await this.viewModel.DeleteProduct(this);
            });
        }