Example #1
0
        public SpecificationVersionEditViewModel(IDataService <LabDbEntities> labDbData,
                                                 IEventAggregator eventAggregator,
                                                 ISpecificationService specificationService)
        {
            _specificationService = specificationService;
            _editMode             = false;
            _eventAggregator      = eventAggregator;
            _labDbData            = labDbData;


            DeleteRequirementCommand = new DelegateCommand <Requirement>(
                req =>
            {
                req.Delete();

                _specificationVersionInstance.Load();

                GenerateRequirementList();

                RaisePropertyChanged("RequirementList");
            });

            SaveCommand = new DelegateCommand(
                () =>
            {
                _specificationVersionInstance.Update();

                if (_specificationVersionInstance == null)
                {
                    return;
                }

                if (_specificationVersionInstance.IsMain)
                {
                    _specificationService.UpdateRequirements(_requirementList.Select(req => req.RequirementInstance));
                }
                else
                {
                    _specificationService.UpdateRequirements(_requirementList.Where(req => req.IsOverride)
                                                             .Select(req => req.RequirementInstance));
                }

                EditMode = false;
            },
                () => _editMode &&
                !HasErrors);

            StartEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = true;
            },
                () => CanEdit && !_editMode);

            StartTestListEditCommand = new DelegateCommand(
                () =>
            {
                NavigationToken token = new NavigationToken(SpecificationViewNames.AddMethod,
                                                            null,
                                                            RegionNames.SpecificationVersionTestListEditRegion);

                _eventAggregator.GetEvent <NavigationRequested>()
                .Publish(token);
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.SpecificationEdit));

            _eventAggregator.GetEvent <SpecificationMethodListChanged>()
            .Subscribe(
                spc =>
            {
                if (spc.ID == _specificationVersionInstance.SpecificationID)
                {
                    GenerateRequirementList();
                    RaisePropertyChanged("RequirementList");
                }
            });
        }