示例#1
0
        public ComplectTypesViewModel(IEnumerable <Parameter> items, IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
            Items       = new ObservableCollection <Parameter>(items);

            SelectCommand = new DelegateCommand(
                () =>
            {
                IsSelected = true;
                SelectEvent?.Invoke();
            },
                () => SelectedItem != null);

            NewTypeCommand = new DelegateCommand(
                () =>
            {
                var complectTypeWindow = new ComplectTypeWindow(_unitOfWork.Repository <ParameterGroup>().GetById(GlobalAppProperties.Actual.ComplectsGroup.Id));
                complectTypeWindow.ShowDialog();
                if (complectTypeWindow.IsOk)
                {
                    complectTypeWindow.ParameterComplectType.AcceptChanges();
                    var parameter = complectTypeWindow.ParameterComplectType.Model;
                    var relation  = new ParameterRelation();
                    relation.RequiredParameters.Add(_unitOfWork.Repository <Parameter>().GetById(GlobalAppProperties.Actual.ComplectsParameter.Id));
                    parameter.ParameterRelations.Add(relation);
                    relation.ParameterId = parameter.Id;

                    Items.Add(parameter);
                    SelectedItem = parameter;
                }
            });
        }
        protected override void AfterLoading()
        {
            //новый продукт
            var block = new ProductBlockWrapper(new ProductBlock());

            Item.Product = new ProductWrapper(new Product())
            {
                ProductBlock = block
            };

            //параметры продукта
            _parameter = new ParameterWrapper(new Parameter());
            var group = UnitOfWork.Repository <ParameterGroup>().GetById(GlobalAppProperties.Actual.NewProductParameterGroup.Id);

            _parameter.ParameterGroup = new ParameterGroupWrapper(group);

            var parameterBase = UnitOfWork.Repository <Parameter>().GetById(GlobalAppProperties.Actual.NewProductParameter.Id);
            var relation      = new ParameterRelation();

            relation.RequiredParameters.Add(parameterBase);
            _parameter.ParameterRelations.Add(new ParameterRelationWrapper(relation));

            var parameters = parameterBase.Paths().First().Parameters.Select(x => new ParameterWrapper(x)).ToList();

            parameters.Add(_parameter);
            parameters.ForEach(x => block.Parameters.Add(x));

            Item.PropertyChanged += ItemOnPropertyChanged;

            base.AfterLoading();
        }