Beispiel #1
0
        public TEntity Get(int id)
        {
            if (id < 1)
            {
                throw new ArgumentOutOfRangeException(NameOf.nameof(() => id));
            }

            return(_entities.FirstOrDefault(e => e.Id == id));
        }
Beispiel #2
0
        public bool Has(int id)
        {
            if (id < 1)
            {
                throw new ArgumentOutOfRangeException(NameOf.nameof(() => id));
            }

            return(_entities.Any(e => e.Id == id));
        }
Beispiel #3
0
        public int Add(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(NameOf.nameof(() => entity));
            }

            _entities.Add(entity);
            _context.SaveChanges();

            return(entity.Id);
        }
Beispiel #4
0
        public void Remove(int id)
        {
            if (id < 1)
            {
                throw new ArgumentOutOfRangeException(NameOf.nameof(() => id));
            }

            var entity = this.Get(id);

            if (entity == null)
            {
                return;
            }

            _entities.Remove(entity);
            _context.SaveChanges();
        }