Example #1
0
        public async Task <T> Delete(T entity)
        {
            _context.Remove(entity);
            await _context.SaveChangesAsync();

            return(entity);
        }
Example #2
0
        public void Delete(int id)
        {
            var entitiy = Сontext.Find(id);

            if (entitiy != null)
            {
                Сontext.Remove(entitiy);
            }
        }
Example #3
0
 protected virtual Task <int> DeleteOneAsync(int id)
 {
     return(Task.Run(async() =>
     {
         var user = await GetOneAsync(id);
         _efDbContext.Remove(user);
         return _efDbContext.SaveChanges();
     }));
 }
Example #4
0
        public void Remove(int id)
        {
            var area = FindById(id);

            if (_context.GoodsItems.Any(gi => gi.AreaId == id))
            {
                throw new InvalidOperationException("Cannot remove an area that has items inside.");
            }
            _context.Remove(area);
            _context.SaveChanges();
        }
Example #5
0
        public ResultModel Delete(object key)
        {
            var entityData = _context.SchoolPost.Find(key);

            _context.Remove(entityData);
            var result = _context.SaveChanges();

            return(new ResultModel
            {
                Result = result > 0 ? ResultModelType.Success : ResultModelType.Error
            });
        }
Example #6
0
        public void Verify_QueriesMethods_WorksProperly()
        {
            int setCalls = 0;

            var dbsetMock = new Mock <DbSet <TestEntity> >();

            var dbModelMock = new Mock <EfDbModel>();

            dbModelMock.Setup(x => x.Set <TestEntity>()).Returns(dbsetMock.Object);

            Func <string, EfDbModel> createDbContextBehaviour = (cs) =>
            {
                return(dbModelMock.Object);
            };

            var dbContext = new EfDbContext(createDbContextBehaviour);

            dbContext.CreateDbContext();

            var queryable = dbContext.Query <TestEntity>();

            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));

            dbContext.Add(new TestEntity());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.Add(It.IsAny <TestEntity>()), Times.Once());

            dbContext.AddRange(new List <TestEntity>());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.AddRange(It.IsAny <List <TestEntity> >()), Times.Once());

            dbContext.Remove(new TestEntity());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.Remove(It.IsAny <TestEntity>()), Times.Once());

            dbContext.RemoveRange(new List <TestEntity>());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.RemoveRange(It.IsAny <List <TestEntity> >()), Times.Once());
        }
Example #7
0
 public void Excluir(TEntity entidade)
 {
     _efbdcontext.Remove(entidade);
     _efbdcontext.SaveChanges();
 }