Пример #1
0
        public virtual bool Delete(T item)
        {
            bool deleteResult  = false;
            var  publisherById = _curDapperRep.GetById(item.Id);

            if (publisherById != null)
            {
                var mapper       = new MapperConfiguration(cfg => cfg.CreateMap <T, K>()).CreateMapper();
                var itemToDelete = mapper.Map <T, K>(item);
                try
                {
                    deleteResult = _curDapperRep.Delete(itemToDelete);
                    return(deleteResult);
                }
                catch (Exception)
                {
                    Console.WriteLine("Current item has external links, cant delete");
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
    public async Task GivenRepository_WhenFullCRUDFlowIsRun_ThenSucceed()
    {
        Execute(Structure.UsersCreateSql);

        var repository = new DapperRepository <User>(DbConnection, new NulloAggregateEventsPublisher());

        var user = new User {
            Id = 0, UserName = "******", FullName = null
        };

        //1. Add
        var result = await repository.Add(user);

        result.Should().NotBe(null);
        result.Id.Should().BeGreaterThan(0);
        result.UserName.Should().Be("*****@*****.**");
        result.FullName.Should().BeNull();

        //2. GetById

        var recordFromDb = await repository.FindById(user.Id);

        recordFromDb.Should().BeEquivalentTo(result);

        //3. Update
        var userToUpdate = new User {
            Id = user.Id, UserName = "******", FullName = "Tom Smith"
        };

        result = await repository.Update(userToUpdate);

        result.Should().NotBe(null);
        result.Id.Should().Be(user.Id);
        result.UserName.Should().Be("*****@*****.**");
        result.FullName.Should().Be("Tom Smith");

        recordFromDb = await repository.FindById(userToUpdate.Id);

        recordFromDb.Should().BeEquivalentTo(result);

        //4. Remove
        result = await repository.Delete(userToUpdate);

        result.Should().NotBe(null);
        result.Id.Should().Be(user.Id);
        result.UserName.Should().Be("*****@*****.**");
        result.FullName.Should().Be("Tom Smith");

        recordFromDb = await repository.FindById(userToUpdate.Id);

        recordFromDb.Should().Be(null);

        //5. Add Range

        var results = (await repository.AddAll(
Пример #3
0
        public void Delete()
        {
            ClearDapperCompisiteKeyEntity();
            var d1 = CreateDapperCompisiteKeyEntity();

            try
            {
                var ins   = _dapper.Delete(d1);
                var sql   = $"select count(*) from dapper_compisite_key where products_id = {d1.products_id} and language_id = {d1.language_id}";
                var count = helper.GetValue(sql, Convert.ToInt32);
                Assert.Equal(count, 0);
            }
            finally
            {
                ClearDapperCompisiteKeyEntity();
            }
        }
Пример #4
0
        /// <summary>
        ///     删除支出记录
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userContext"></param>
        /// <returns></returns>
        public ResponseModel DeleteExpenses(int id, UserContext userContext)
        {
            var request = new PayRecord
            {
                Id = id
            };

            //1.删除支出分类数据
            var result = _expensesRepository.Delete(request);

            //2.返回删除支出分类实体
            return(new ResponseModel
            {
                Code = result ? (int)ErrorCodeEnum.Success : (int)ErrorCodeEnum.ExpenseFailed,
                Data = id
            });
        }
Пример #5
0
 public void Delete()
 {
     ClearTestEntity();
     try
     {
         var d1 = CreateTestEntity();
         _dapper.Delete(new DapperAllTest {
             Id = d1.Id
         });
         var sql   = string.Format("select count(*) from DapperAllTest where id = {0}", d1.Id);
         int count = helper.GetValue(sql, Convert.ToInt32);
         Assert.Equal(0, count);
     }
     finally
     {
         ClearTestEntity();
     }
 }
Пример #6
0
 public void Delete()
 {
     ClearDapperTestEntity();
     try
     {
         var d1 = CreateDapperTestEntity();
         _dapper.Delete(new DapperTestEntity {
             id = d1.id
         });
         var sql   = string.Format("select count(*) from dapper_all_test where id = {0}", d1.id);
         int count = helper.GetValue(sql, Convert.ToInt32);
         Assert.Equal(count, 0);
     }
     finally
     {
         ClearDapperTestEntity();
     }
 }
Пример #7
0
        /// <summary>
        ///     删除支出分类
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userContext"></param>
        /// <returns></returns>
        public ResponseModel DeleteExpenseCategory(int id, UserContext userContext)
        {
            //1.删除支出分类数据
            var request = new PayClass
            {
                Id = id
            };
            var result = _expensesCategoryRepository.Delete(request);

            //2.更新Redis缓存数据
            if (result)
            {
                UpdateRedisPayClassCatch(userContext);
            }

            //3.返回删除支出分类实体
            return(new ResponseModel
            {
                Code = result ? (int)ErrorCodeEnum.Success : (int)ErrorCodeEnum.ExpenseFailed,
                Data = id
            });
        }
Пример #8
0
 public void Delete(int id)
 {
     Repository.Delete(id);
 }
Пример #9
0
 public int Delete(object primaryKeyValue)
 {
     return(dapper.Delete(primaryKeyValue) ? 1 : 0);
 }
Пример #10
0
        public void GivenRepository_WhenFullCRUDFlowIsRun_ThenSucceed()
        {
            Execute(Structure.UsersCreateSql);

            var repository = new DapperRepository <User>(DbConnection);

            var user = new User {
                Id = 0, UserName = "******", FullName = null
            };

            //1. Add
            var result = repository.Add(user);

            result.Should().NotBe(null);
            result.Id.Should().BeGreaterThan(0);
            result.UserName.Should().Be("*****@*****.**");
            result.FullName.Should().BeNull();

            //2. GetById

            var recordFromDb = repository.FindById(user.Id);

            recordFromDb.Should().BeEquivalentTo(result);

            //3. Update
            var userToUpdate = new User {
                Id = user.Id, UserName = "******", FullName = "Tom Smith"
            };

            result = repository.Update(userToUpdate);

            result.Should().NotBe(null);
            result.Id.Should().Be(user.Id);
            result.UserName.Should().Be("*****@*****.**");
            result.FullName.Should().Be("Tom Smith");

            recordFromDb = repository.FindById(userToUpdate.Id);

            recordFromDb.Should().BeEquivalentTo(result);

            //4. Remove
            result = repository.Delete(userToUpdate);

            result.Should().NotBe(null);
            result.Id.Should().Be(user.Id);
            result.UserName.Should().Be("*****@*****.**");
            result.FullName.Should().Be("Tom Smith");

            recordFromDb = repository.FindById(userToUpdate.Id);

            recordFromDb.Should().Be(null);

            //5. Add Range

            var results = repository.AddAll(
                new User {
                UserName = "******"
            },
                new User {
                UserName = "******"
            },
                new User {
                UserName = "******"
            }
                )?.ToList();

            results.Should().NotBeNull();
            results.Should().HaveCount(3);

            results[0].Id.Should().BeGreaterThan(0);
            results[0].UserName.Should().Be("*****@*****.**");
            results[0].FullName.Should().BeNull();

            results[1].Id.Should().BeGreaterThan(0);
            results[1].UserName.Should().Be("*****@*****.**");
            results[1].FullName.Should().BeNull();

            results[2].Id.Should().BeGreaterThan(0);
            results[2].UserName.Should().Be("*****@*****.**");
            results[2].FullName.Should().BeNull();

            //6. Query

            var queryResults = repository.Query().ToList();

            queryResults.Should().Contain(x => results.Select(u => u.Id).Contains(x.Id));

            queryResults = repository.Query().ToList().Where(x => x.UserName == results[1].UserName).ToList();

            queryResults.Should().HaveCountGreaterOrEqualTo(1);
            queryResults.First(x => x.Id == results[1].Id).Should().BeEquivalentTo(results[1]);
        }
Пример #11
0
 public bool Delete(TEntity instance, IDbTransaction transaction)
 {
     return(ExecuteWithTryCatch(() => _internalRepository.Delete(instance, transaction)));
 }