/// <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)); }