示例#1
0
 internal void RemoveCreatureColor([NotNull] CreatureColorEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     if (entity.IsReadOnly)
     {
         return;
     }
     grangerSimpleDb.CreatureColors.Remove(entity.Id);
     grangerSimpleDb.FlagAsChanged();
     OnCreatureColorsModified?.Invoke(this, new EventArgs());
 }
示例#2
0
        /// <summary>
        /// Adds the color if it does not yet exist in the database.
        /// </summary>
        /// <param name="entity"></param>
        internal void SeedCreatureColor([NotNull] CreatureColorEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            CreatureColorEntity existingEntity;

            if (!grangerSimpleDb.CreatureColors.TryGetValue(entity.Id, out existingEntity))
            {
                grangerSimpleDb.CreatureColors.Add(entity.Id, entity);
                OnCreatureColorsModified?.Invoke(this, new EventArgs());
            }
        }
示例#3
0
        internal void AddOrUpdateCreatureColor([NotNull] CreatureColorEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            CreatureColorEntity existingEntity;

            if (!grangerSimpleDb.CreatureColors.TryGetValue(entity.Id, out existingEntity))
            {
                grangerSimpleDb.CreatureColors.Add(entity.Id, entity);
            }
            else
            {
                if (existingEntity.IsReadOnly)
                {
                    throw new InvalidOperationException($"Existing {nameof(CreatureColorEntity)} with Id: {entity.Id} is flagged ReadOnly.");
                }

                grangerSimpleDb.CreatureColors[entity.Id] = entity;
            }
            grangerSimpleDb.FlagAsChanged();
            OnCreatureColorsModified?.Invoke(this, new EventArgs());
        }