/// <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); }
public NewEnvironmentViewModelBase() { Validator = new EnvironmentViewModelValidator(); DataAdapter = new EnvironmentDataAdapter(App.GetConnectionString()); }