Beispiel #1
0
        public void Delete(IValueSet valueSet)
        {
            if (valueSet.IsCustom && this.isCustomValue.Get(valueSet) && !valueSet.IsNew())
            {
                Deleting?.Invoke(this, valueSet);

                this.repository.Delete(valueSet);

                Deleted?.Invoke(this, valueSet);

                return;
            }

            throw new InvalidOperationException("ValueSet was not a custom value set and cannot be deleted.");
        }
Beispiel #2
0
        /// <summary>
        /// Saves a <see cref="IValueSet"/>
        /// </summary>
        /// <param name="valueSet">The <see cref="IValueSet"/> to be saved</param>
        /// <remarks>
        /// At this point, we can only save "new" value sets.  Updates are out of scope at the moment - To be discussed.
        /// </remarks>
        public void Save(IValueSet valueSet)
        {
            if (valueSet.IsCustom && this.isCustomValue.Get(valueSet) && valueSet.IsNew())
            {
                Saving?.Invoke(this, valueSet);

                var attempt = this.repository.Add(valueSet);
                if (attempt.Success && attempt.Result.HasValue)
                {
                    Saved?.Invoke(this, attempt.Result.Single());
                    return;
                }

                if (!attempt.Exception.HasValue)
                {
                    throw new ValueSetOperationException(
                              "An exception was not returned by the attempt to save a ValueSet but the save failed.");
                }

                throw attempt.Exception.Single();
            }

            throw new InvalidOperationException("ValueSet was not a custom value set and cannot be saved.");
        }