public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();

            /*
             *  测试 sql 查询
             */
            var queryBySql = await _blogArticleServices.QuerySql("SELECT bsubmitter,btitle,bcontent,bCreateTime FROM BlogArticle WHERE bID>5");

            /*
             *  测试按照指定列查询
             */
            var queryByColums = await _blogArticleServices
                                .Query <BlogViewModels>(it => new BlogViewModels()
            {
                btitle = it.btitle
            });

            /*
             *  测试按照指定列查询带多条件和排序方法
             */
            Expression <Func <BlogArticle, bool> > registerInfoWhere = a => a.btitle == "xxx" && a.bRemark == "XXX";
            var queryByColumsByMultiTerms = await _blogArticleServices
                                            .Query <BlogArticle>(it => new BlogArticle()
            {
                btitle = it.btitle
            }, registerInfoWhere, "bID Desc");

            /*
             *  测试 sql 更新
             *
             * 【SQL参数】:@bID:5
             *  @bsubmitter:laozhang619
             *  @IsDeleted:False
             * 【SQL语句】:UPDATE `BlogArticle`  SET
             *  `bsubmitter`=@bsubmitter,`IsDeleted`=@IsDeleted  WHERE `bID`=@bID
             */
            var updateSql = await _blogArticleServices.Update(new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}", IsDeleted = false, bID = 5 });


            // 测试模拟异常,全局异常过滤器拦截
            var i = 0;
            var d = 3 / i;


            // 测试 AOP 缓存
            var blogArticles = await _blogArticleServices.GetBlogs();


            // 测试多表联查
            var roleModulePermissions = await _roleModulePermissionServices.QueryMuchTable();


            // 测试多个异步执行时间
            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();
            var ad             = await roleModuleTask;
            var list           = await listTask;


            // 测试service层返回异常
            _advertisementServices.ReturnExp();

            return(data);
        }
Exemple #2
0
 public async Task <List <Advertisement> > GetInfoByIdAsync(int id)
 {
     //IAdvertisementServices dal = new AdvertisementServices();
     return(await _services.Query(d => d.Id == id));
 }