Esempio n. 1
0
        /// <summary>
        /// Constructs a new <see cref="CmdExecutor"/> object, initializes its command queue and sets the <see cref="TargetEnvironment"/> property.
        /// </summary>
        /// <param name="targetEnvironmentViewModel">The target environment which will participate in the <see cref="EnvironmentChanged"/> event.</param>
        /// <seealso cref="CmdExecutorBase"/>
        public CmdExecutor(EnvironmentViewModel targetEnvironmentViewModel)
        {
            var converter            = new EnvironmentConverter();
            var convertedEnvironment = converter.From(targetEnvironmentViewModel);

            TargetEnvironment = convertedEnvironment;
        }
Esempio n. 2
0
        /// <summary>
        /// Converts an <see cref="EnvironmentViewModel"/> to an <see cref="Environment"/> entity and inserts it if it's not been persisted yet. If it has, updates it.
        /// </summary>
        /// <param name="environment">The <see cref="EnvironmentViewModel"/> to save or update.</param>
        /// <returns>The newly-inserted or updated <see cref="Environment"/>, converted to an <see cref="EnvironmentViewModel"/></returns>
        public EnvironmentViewModel SaveEnvironment(EnvironmentViewModel environment)
        {
            var converter = new EnvironmentConverter();
            var entity    = converter.From(environment);
            var inserted  = _repository.UpsertEnvironment(entity);

            return(converter.To(inserted));
        }
Esempio n. 3
0
        /// <summary>
        /// Validates the supplied <see cref="EnvironmentViewModel"/>. If the validation is successful, converts to an <see cref="Environment"/> entity and inserts it in the datastore.
        /// </summary>
        /// <param name="environmentViewModel">The <see cref="EnvironmentViewModel"/> to insert.</param>
        /// <returns>If the validation is successful, return a new instance of the <see cref="EnvironmentViewModel"/> with its id updated. Otherwise, returns null.</returns>
        public EnvironmentViewModel InsertEnvironment(EnvironmentViewModel environmentViewModel)
        {
            var validator        = new EnvironmentViewModelValidator();
            var validationResult = validator.Validate(environmentViewModel);

            if (validationResult.IsValid)
            {
                var converter = new EnvironmentConverter();
                var converted = converter.From(environmentViewModel);
                var inserted  = _repository.InsertEnvironment(converted);
                return(converter.To(inserted));
            }

            return(null);
        }