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

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

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

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

            return(entity.Id);
        }
예제 #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();
        }