Пример #1
0
        protected JobViewModelBase(T job, AbstractValidator <T> validator, IDataClient client, IDialogCoordinator dialogCoordinator, object dialogContext) : base(job, validator)
        {
            PreChangeName = job.Name;
            //Note the use of job vs Job below. The parameter has the type T which is necessary for the  client stuff to work
            Job = job;

            //Save job
            var saveCanExecute = this
                                 .WhenAnyValue(x => x.HasErrors)
                                 .Select(x => x == false);

            Save = ReactiveCommand.CreateFromTask(async _ =>
            {
                //First delete the existing job (if there is an existing job), with the old name
                string tmpName = Name;
                Name           = PreChangeName;
                await client.DeleteJob(job).ConfigureAwait(true); //failure is OK here, it might not exist on the server if it's newly added
                Name = tmpName;

                //then add it with the new values
                var result = await client.AddJob(job).ConfigureAwait(true);
                if (await result.DisplayErrors(dialogContext, dialogCoordinator).ConfigureAwait(true))
                {
                    return;
                }
                PreChangeName = Name;
            },
                                                  saveCanExecute);

            //this is here because we need to know the job type
            Delete = ReactiveCommand.CreateFromTask(async _ => (ApiResponse)await client.DeleteJob(job).ConfigureAwait(false));
        }
Пример #2
0
        protected JobViewModelBase(T job, AbstractValidator <T> validator, IDataClient client, IDialogCoordinator dialogCoordinator) : base(job, validator)
        {
            PreChangeName = job.Name;
            Job           = job;
            _typedJob     = job;

            //Save job
            var saveCanExecute = this
                                 .WhenAnyValue(x => x.HasErrors)
                                 .Select(x => x == false);

            Save = ReactiveCommand.CreateFromTask(async _ =>
            {
                //First delete the existing job (if there is an existing job), with the old name
                string tmpName = Name;
                Name           = PreChangeName;
                await client.DeleteJob(_typedJob); //failure is OK here, it might not exist on the server if it's newly added
                Name = tmpName;

                //then add it with the new values
                var result = await client.AddJob(_typedJob).ConfigureAwait(true);
                if (await result.DisplayErrors(this, dialogCoordinator))
                {
                    return;
                }

                PreChangeName = Name;
            },
                                                  saveCanExecute);
        }