/// <summary>
        /// Updates the <see cref="SpecializationGroup"/>.
        /// </summary>
        /// <returns>Updated <see cref="SpecializationGroup"/>.</returns>
        /// <param name="g">The new <see cref="SpecializationGroup"/> state.</param>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="LeafRPCException"/>
        /// <exception cref="DbException"/>
        public async Task <SpecializationGroup> UpdateAsync(SpecializationGroup g)
        {
            ThrowIfInvalid(g);

            try
            {
                var updated = await svc.UpdateAsync(g);

                if (updated != null)
                {
                    log.LogInformation("Updated SpecializationGroup:{@SpecializationGroup}", updated);
                }
                else
                {
                    log.LogInformation("Could not update SpecializationGroup:{@SpecializationGroup}, not found", g);
                }
                return(updated);
            }
            catch (DbException de)
            {
                log.LogInformation("Failed to update SpecializationGroup. SpecializationGroup:{@SpecializationGroup} Code:{Code} Error:{Error}", g, de.ErrorCode, de.Message);
                de.MapThrow();
                throw;
            }
        }
        /// <summary>
        /// Creates a new <see cref="SpecializationGroup"/>.
        /// </summary>
        /// <returns>Created <see cref="SpecializationGroup"/>.</returns>
        /// <param name="g">New <see cref="SpecializationGroup"/>.</param>
        public async Task <SpecializationGroup> CreateAsync(SpecializationGroup g)
        {
            ThrowIfInvalid(g);
            if (g.Specializations?.Any(s => string.IsNullOrWhiteSpace(s.SqlSetWhere) || string.IsNullOrWhiteSpace(s.UiDisplayText)) ?? false)
            {
                throw new ArgumentException($"{nameof(SpecializationGroup)}.{nameof(SpecializationGroup.Specializations)} contains malfored specializations.");
            }

            try
            {
                var created = await svc.CreateAsync(g);

                log.LogInformation("Created SpecializationGroup:{@SpecializationGroup}", created);
                return(created);
            }
            catch (DbException de)
            {
                log.LogError("Failed to create SpecializationGroup. SpecializationGroup:{@SpecializationGroup} Code:{Code} Error:{Error}", g, de.ErrorCode, de.Message);
                de.MapThrow();
                throw;
            }
        }
 void ThrowIfInvalid(SpecializationGroup g)
 {
     Ensure.NotNull(g, nameof(g));
     Ensure.NotNullOrWhitespace(g.UiDefaultText, nameof(g.UiDefaultText));
 }