Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NidaDrugQuestionnaireViewModel"/> class.
        /// </summary>
        /// <param name="userDialogService">The user dialog service.</param>
        /// <param name="asyncRequestDispatcherFactory">The async request dispatcher factory.</param>
        /// <param name="accessControlManager">The access control manager.</param>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="commandFactory">The command factory.</param>
        public NidaDrugQuestionnaireViewModel(
            IUserDialogService userDialogService,
            IAsyncRequestDispatcherFactory asyncRequestDispatcherFactory,
            IAccessControlManager accessControlManager,
            IEventAggregator eventAggregator,
            ICommandFactory commandFactory)
            : base(userDialogService, asyncRequestDispatcherFactory, accessControlManager, eventAggregator, commandFactory)
        {
            _eventAggregator = eventAggregator;
            _asyncRequestDispatcherFactory = asyncRequestDispatcherFactory;
            _userDialogService             = userDialogService;

            var commandFactoryHelper = CommandFactoryHelper.CreateHelper(this, commandFactory);

            SaveCommand = commandFactoryHelper.BuildDelegateCommand <KeyedDataTransferObject> (
                () => SaveCommand,
                dto =>
            {
                var name = PropertyUtil.ExtractPropertyName(() => EditingDto);
                if (dto != null && EditingDto.GetType() != dto.GetType())
                {
                    name = EditingDto.GetType().GetProperties().First(pi => pi.PropertyType == dto.GetType()).Name;
                }
                return(name);
            },
                ExecuteSaveCommand,
                CanExecuteSaveCommand);

            var ruleExecutor = new NotifyPropertyChangedRuleExecutor <NidaDrugQuestionnaireViewModel, IDataTransferObject> ();

            ruleExecutor.AddRunAllRulesProperty(vm => vm.EditingDto);
            ruleExecutor.WatchSubject(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgramOfferingEditorViewModel"/> class.
        /// </summary>
        /// <param name="userDialogService">The user dialog service.</param>
        /// <param name="asyncRequestDispatcherFactory">The async request dispatcher factory.</param>
        /// <param name="accessControlManager">The access control manager.</param>
        /// <param name="commandFactory">The command factory.</param>
        /// <param name="popupService">The popup service.</param>
        public ProgramOfferingEditorViewModel(
            IUserDialogService userDialogService,
            IAsyncRequestDispatcherFactory asyncRequestDispatcherFactory,
            IAccessControlManager accessControlManager,
            ICommandFactory commandFactory,
            IPopupService popupService)
            : base(userDialogService, asyncRequestDispatcherFactory, accessControlManager, commandFactory)
        {
            _userDialogService             = userDialogService;
            _asyncRequestDispatcherFactory = asyncRequestDispatcherFactory;
            _popupService = popupService;

            CreateCommand = NavigationCommandManager.BuildCommand(() => CreateCommand, NavigateToCreateCommand);
            EditCommand   = NavigationCommandManager.BuildCommand(() => EditCommand, NavigateToEditCommand);

            var commandFactoryHelper = CommandFactoryHelper.CreateHelper(this, commandFactory);

            SaveCommand = commandFactoryHelper.BuildDelegateCommand <KeyedDataTransferObject> (
                () => SaveCommand,
                dto =>
            {
                var name = PropertyUtil.ExtractPropertyName(() => EditingDto);
                if (dto != null && EditingDto.GetType() != dto.GetType())
                {
                    name = EditingDto.GetType().GetProperties().First(pi => pi.PropertyType == dto.GetType()).Name;
                }
                return(name);
            },
                ExecuteSaveCommand,
                CanExecuteSaveCommand);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Requests the completed.
        /// </summary>
        /// <param name="receivedResponses">The received responses.</param>
        protected virtual void RequestCompleted(ReceivedResponses receivedResponses)
        {
            _editingPart.IsLoading = false;

            var response        = receivedResponses.Responses.ElementAt(0) as IDtoResponse;
            var responseDtoType = response.GetType().GetGenericArguments().ElementAt(0);

            if (responseDtoType == EditingDto.GetType())
            {
                EditingDto = response.GetDto() as TDto;
            }
            else
            {
                foreach (var propInfo in EditingDto.GetType().GetProperties())
                {
                    if (propInfo.PropertyType == responseDtoType)
                    {
                        propInfo.SetValue(
                            EditingDto, response.GetDto(), BindingFlags.SetProperty, null, null, Thread.CurrentThread.CurrentCulture);
                        break;
                    }
                }
            }
        }