Exemplo n.º 1
0
        /// <summary>
        /// KarveToolBarViewModel is a view model to modle the toolbar behaviour.
        /// </summary>
        /// <param name="dataServices">Service for fetching datas</param>
        /// <param name="eventManager">Service for communicate with other view models</param>
        /// <param name="careKeeper">Service for caring command and storing/undoing command</param>
        /// <param name="regionManager">Service for region handling</param>
        /// <param name="dialogService">Service for spotting the dialog</param>
        /// <param name="configurationService">Service for the configuraration parameters</param>
        public KarveToolBarViewModel(IDataServices dataServices,
                                     IEventManager eventManager,
                                     ICareKeeperService careKeeper,
                                     IRegionManager regionManager,
                                     IDialogService dialogService,
                                     IConfigurationService configurationService) : base(dataServices, null, dialogService, configurationService)
        {
            this._dictionary           = SubsystemFactory.GetSubsytem();
            this._dataServices         = dataServices;
            this._dialogService        = dialogService;
            this._configurationService = configurationService;
            this._eventManager         = eventManager;
            this._eventManager.RegisterObserverToolBar(this);
            this._careKeeper           = careKeeper;
            this.SaveCommand           = new DelegateCommand(DoSaveCommand);
            this.NewCommand            = new DelegateCommand(DoNewCommand);
            this.DeleteCommand         = new DelegateCommand <object>(DoDeleteCommand);
            this._dataServices         = dataServices;
            this._configurationService = configurationService;
            this._eventManager         = eventManager;
            this._eventManager.RegisterObserverToolBar(this);
            this.CurrentSaveImagePath = currentSaveImage;
            _regionManager            = regionManager;
            _states              = ToolbarStates.None;
            _noActiveValue       = string.Empty;
            this.IsSaveEnabled   = false;
            this.IsDeleteEnabled = false;
            this.IsNewEnabled    = false;
            ConfirmationRequest  = new InteractionRequest <IConfirmation>();
            Confirmation request = new Confirmation
            {
                Title   = "Confirmacion",
                Content = confirmDelete
            };

            ViewModelUri        = new Uri("karve://toolbar/viewmodel?id=" + UniqueId);
            ConfirmationCommand = new DelegateCommand(() =>
            {
                // string noActiveValue = configurationService.GetPrimaryKeyValue();
                request.Content = confirmDelete;
                ConfirmationRequest.Raise(request);
                if (request.Confirmed)
                {
                    string value   = string.Empty;
                    var singleView = _regionManager.Regions[RegionNames.TabRegion].ActiveViews.FirstOrDefault();
                    if (singleView != null)
                    {
                        var headerProp = singleView.GetType().GetProperty("Header");
                        if (headerProp != null)
                        {
                            if (headerProp.GetValue(singleView) is string header)
                            {
                                value = header.Split('.')[0];
                            }
                        }
                    }

                    DeleteCommand.Execute(value);
                }
            });
            SaveValueCommand = new DelegateCommand(() =>
            {
                request.Content = confirmSave;

                ConfirmationRequest.Raise(request);
                if (request.Confirmed)
                {
                    SaveCommand.Execute();
                }
                else
                {
                    this.CurrentSaveImagePath = KarveToolBarViewModel.currentSaveImage;
                }
            });

            AddValidationChain();
            _uniqueId = ObserverName + Guid.NewGuid();
        }