public ProductsIncludedViewModel(ProductIncludedWrapper wrapper, IUnitOfWork unitOfWork, IUnityContainer container) : base(container)
        {
            ViewModel = container.Resolve <ProductIncludedDetailsViewModel>();
            ViewModel.Load(wrapper, unitOfWork);
            if (ViewModel.Item.Product == null)
            {
                var productIncludedDefault = GlobalAppProperties.Actual.ProductIncludedDefault;
                if (productIncludedDefault != null)
                {
                    ViewModel.Item.Product = new ProductWrapper(unitOfWork.Repository <Product>().GetById(productIncludedDefault.Id));
                }
            }

            OkCommand = new DelegateLogCommand(
                () =>
            {
                CloseRequested?.Invoke(this, new DialogRequestCloseEventArgs(true));
            },
                () =>
            {
                return(ViewModel?.Item.Product != null && ViewModel.Item.Amount > 0);
            });
            ViewModel.Item.PropertyChanged += (s, a) => OkCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 2
0
        protected BaseGroupsViewModel(IUnityContainer container) : base(container)
        {
            AddCommand    = new DelegateLogCommand(AddCommand_Execute, AddCommand_CanExecute);
            RemoveCommand = new DelegateLogCommand(RemoveCommand_Execute, () => Groups.SelectedGroup != null);

            ChangeFacilityCommand = new DelegateCommand <TGroup>(ChangeFacilityCommand_Execute);
            ChangeProductCommand  = new DelegateCommand <TGroup>(ChangeProductCommand_Execute);
            ChangePaymentsCommand = new DelegateCommand <TGroup>(ChangePaymentsCommand_Execute);

            #region ProductIncludedCommands

            //добавление включенного оборудования
            AddProductIncludedCommand = new DelegateLogCommand(
                () =>
            {
                var productIncludedWrapper    = new ProductIncludedWrapper(new ProductIncluded());
                var productsIncludedViewModel = new ProductsIncludedViewModel(productIncludedWrapper, UnitOfWork, Container);
                var dr = Container.Resolve <IDialogService>().ShowDialog(productsIncludedViewModel);
                if (!dr.HasValue || !dr.Value)
                {
                    return;
                }
                Groups.SelectedGroup.AddProductIncluded(productsIncludedViewModel.ViewModel.Entity, productsIncludedViewModel.IsForEach);
                RefreshPrice(Groups.SelectedGroup);
            },
                () => Groups.SelectedGroup != null);

            //удаление включенного оборудования
            RemoveProductIncludedCommand = new DelegateLogCommand(
                () =>
            {
                if (Container.Resolve <IMessageService>().ShowYesNoMessageDialog("Удаление", "Удалить?", defaultNo: true) == MessageDialogResult.No)
                {
                    return;
                }

                Groups.SelectedGroup.RemoveProductIncluded(Groups.SelectedProductIncluded);
                RefreshPrice(Groups.SelectedGroup);
            },
                () => Groups.SelectedProductIncluded != null);

            //установка нестандартной себестоимости шеф-монтажа
            SetCustomFixedPriceCommand = new DelegateLogCommand(
                () =>
            {
                //шеф-монтажи, которые подлежат изменению
                var productsIncludedTarget = Groups
                                             .Where(x => x.Groups != null)
                                             .SelectMany(x => x.Groups)
                                             .SelectMany(x => x.ProductsIncluded)
                                             .Where(x => Equals(x.Model.Id, Groups.SelectedProductIncluded.Model.Id))
                                             .ToList();

                var productIncluded = productsIncludedTarget.Any()
                        ? productsIncludedTarget.Select(x => x.Model).Distinct().Single()
                        : Groups.SelectedProductIncluded.Model;

                var original = productIncluded.CustomFixedPrice;

                var viewModel = new SupervisionPriceViewModel(new ProductIncludedWrapper(productIncluded), UnitOfWork, Container);
                var dr        = Container.Resolve <IDialogService>().ShowDialog(viewModel);
                if (dr.HasValue || dr.Value == true)
                {
                    productsIncludedTarget.ForEach(x => x.CustomFixedPrice = productIncluded.CustomFixedPrice);
                }
                else
                {
                    productsIncludedTarget.ForEach(x => x.CustomFixedPrice = original);
                }

                if (!Equals(productIncluded.CustomFixedPrice, original))
                {
                    RefreshPrice(Groups.SelectedGroup);
                }
            },
                () => Groups.SelectedProductIncluded != null && Groups.SelectedProductIncluded.Model.Product.ProductBlock.IsSupervision);

            #endregion

            Groups.SumChanged += () => { RaisePropertyChanged(nameof(Sum)); };
        }
 public SupervisionPriceViewModel(ProductIncludedWrapper productIncludedWrapper, IUnitOfWork unitOfWork, IUnityContainer container) : base(container)
 {
     Load(productIncludedWrapper, unitOfWork);
 }