コード例 #1
0
        public async Task <PagedResultDto <HomeInfoListDto> > GetPagedNoReadNotice(GetHomeInfosInput input)
        {
            long userID = (long)AbpSession.UserId;
            Expression <Func <HomeInfo, bool> >   predicate  = p => (p.Id != 1);
            Expression <Func <AbpUsersEx, bool> > predicate2 = p => (p.Id == userID);

            if (_userRepository.Count(predicate2).Equals(1))
            {
                input.LastDate = _userRepository.Get(userID).ReadLastNoticeTime;
                predicate      = predicate.And(p => p.CreationTime >= input.LastDate);
            }

            var totalCount = _entityRepository.Count(predicate);

            var entityList = await _entityRepository.GetAll()
                             .Where(r => r.Id != 1)
                             .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), r => (r.Title.Contains(input.FilterText) || r.Description.Contains(input.FilterText)))
                             .WhereIf(input.LastDate.HasValue, r => r.CreationTime > input.LastDate)
                             .OrderByDescending(t => t.Id)
                             //.OrderBy(input.Sorting).AsNoTracking()
                             .PageBy(input)
                             .ToListAsync();

            var entityListDtos = ObjectMapper.Map <List <HomeInfoListDto> >(entityList);

            return(new PagedResultDto <HomeInfoListDto>(totalCount, entityListDtos)); // 第一条记录给 HomeInfo 用
        }
コード例 #2
0
        public int GetVW_SJMXCount()
        {
            Expression <Func <VW_SJMX, bool> > predicate = p => p.器具名称 == "全站仪";

            predicate = predicate.And(p => p.单位名称.Contains("济南"));
            predicate = predicate.And(p => p.送检日期 >= DateTime.Parse("2005-12-21"));
            return(_vwsjmxDapperRepository.Count(predicate));
        }
コード例 #3
0
        public async Task <AuthenticateResultModelEx> AuthenticateEx([FromBody] AuthenticateModel model)
        {
            var loginResult = await GetLoginResultAsync(
                model.UserNameOrEmailAddress,
                model.Password,
                GetTenancyNameOrNull()
                );

            var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));

            long userID = loginResult.User.Id;
            Expression <Func <AbpUsersEx, bool> > predicate2 = p => (p.Id == userID);
            DateTime?lastReadNoticeTime = null;

            if (_userRepository.Count(predicate2).Equals(1))
            {
                lastReadNoticeTime = _userRepository.Get(userID).ReadLastNoticeTime;
            }

            List <string[]> roleNames = _roleNameAppService.GetRoleNames(userID);

            return(new AuthenticateResultModelEx
            {
                AccessToken = accessToken,
                EncryptedAccessToken = GetEncryptedAccessToken(accessToken),
                ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
                UserId = userID,
                SurName = loginResult.User.Surname,
                LastReadNoticeTime = lastReadNoticeTime,
                Roles = roleNames[0],     //  { },
                RoleNames = roleNames[1]  //{ }
            });
        }
コード例 #4
0
        public PagedResultDto <VW_CZRZ> GetPagedCzrzs(GetCzrzInput input)
        {
            Expression <Func <VW_CZRZ, bool> > predicate = p => p.Id > 0;

            if (!input.isAdmin)
            {
                long jdyid = (long)AbpSession.UserId;
                predicate = predicate.And(p => p.UserID == jdyid);
            }

            if (!input.FilterText.IsNullOrWhiteSpace())
            {
                predicate = predicate.And(p => (p.Surname == input.FilterText || p.CZNR.Contains(input.FilterText)));
            }

            var totalCount            = _czrzDapperRepository.Count(predicate);
            IEnumerable <VW_CZRZ> ret = _czrzDapperRepository.GetAllPaged(
                predicate,
                input.SkipCount / input.MaxResultCount,
                input.MaxResultCount,
                input.Sorting, input.Order == "desc"); // input.Order=="asc"  true/false
            List <VW_CZRZ> tempList2 = ObjectMapper.Map <List <VW_CZRZ> >(ret);

            return(new PagedResultDto <VW_CZRZ>(
                       totalCount,
                       tempList2
                       ));
        }
コード例 #5
0
        /// <summary>
        /// 首页未完成列表
        /// JDZT<222
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PagedResultDto <VW_SJCL_100> GetPagedTasks(GetVwSjmxsInput input)
        {
            // 数据库里面必须有 SJMX 实体或者视图
            Expression <Func <VW_SJCL_100, bool> > predicate = p => p.Id > 0;

            if (!input.FilterText.IsNullOrWhiteSpace())
            {
                predicate = predicate.And(p => (p.DWMC.Contains(input.FilterText) || p.ccbh.Contains(input.FilterText) || p.xhggmc.Contains(input.FilterText) || p.QJMC.Contains(input.FilterText)));
            }
            predicate = predicate.And(p => p.JDZT < 222);

            var totalCount = _vwsjclDapperRepository.Count(predicate);
            IEnumerable <VW_SJCL_100> ret = _vwsjclDapperRepository.GetAllPaged(
                predicate,
                input.SkipCount / input.MaxResultCount,
                input.MaxResultCount,
                input.Sorting, input.Order == "desc"); // input.Order=="asc"  true/false
            List <VW_SJCL_100> tempList2 = ObjectMapper.Map <List <VW_SJCL_100> >(ret);

            return(new PagedResultDto <VW_SJCL_100>(
                       totalCount,
                       tempList2
                       ));
        }
コード例 #6
0
        public int DoSomeStuff4()
        {
            //Expression<Func<AbpUsers, bool>> predicate = p => p.Id > 0 && p.Name.Contains("string") ;// && p.QJMCBM.IsIn(roles); // 有 IsIn 但不支持,或者没有 IsIn

            int[]         ints1   = new int[] { 1, 3, 5, 7, 9 };                                     // 没有 Contains,  using System.Linq;
            string[]      nameArr = { "Ha", "Hunter", "Tom", "Lily", "Jay", "Jim", "Kuku", "Locu" }; // 没有 Contains,  using System.Linq;
            List <string> list    = new List <string>(nameArr);
            //list.Contains("Hunter"); //OK
            //new Decimal[] { 85, 86, 88 }.Contains(88);
            List <int> vals = new List <int>()
            {
                1, 3, 5
            };                                   // 有 Contains 但不支持

            Console.WriteLine(vals.Contains(3)); // OK
            //Expression<Func<AbpUsers, bool>> predicate = p => p.Id >0 && vals.Contains(p.CreatorUserId); // 不支持
            //Expression<Func<AbpUsers, bool>> predicate = p => p.Id > 0 && p.EmailAddress.Contains("string"); // OK
            Expression <Func <AbpUsers, bool> > predicate = p => p.Id > 0;

            predicate = predicate.And(p => p.CreatorUserId == 1);
            predicate = predicate.Or(p => p.CreatorUserId == 3); //循环调用解决 in

            return(_userDapperRepository.Count(predicate));
        }
コード例 #7
0
        public PagedResultDto <WTD> GetPagedWtds(GetWtdInput input)
        {
            // 数据库里面必须有 WTD 实体或者视图
            Expression <Func <WTD, bool> > predicate = p => p.Id > 0;

            if (!input.FilterText.IsNullOrWhiteSpace())
            {
                //predicate = predicate.And(p => (p.sjdid==(input.FilterText) || p.dwmc.Contains(input.FilterText)));
                predicate = predicate.And(p => (p.sjdid.Contains(input.FilterText) || p.dwmc.Contains(input.FilterText)));
            }

            var totalCount        = _wtdDapperRepository.Count(predicate);
            IEnumerable <WTD> ret = _wtdDapperRepository.GetAllPaged(
                predicate,
                input.SkipCount / input.MaxResultCount,
                input.MaxResultCount,
                input.Sorting, input.Order == "desc"); // input.Order=="asc"  true/false
            List <WTD> tempList2 = ObjectMapper.Map <List <WTD> >(ret);

            return(new PagedResultDto <WTD>(
                       totalCount,
                       tempList2
                       ));
        }
コード例 #8
0
        /*
         * // 待检定列表 - SJCLAppServices/GetPagedDjmxs
         * public IEnumerable<SJMX> ListDjmxs(string q)
         * {
         *  string strSQL = @"select top 20 a.id,a.sjdid,qjmc,djrq,xhggmc,b.xhggbm,ccbh,zzcnr as zzc,jdy,a.bzsm,g.jdrq,g.jwrq,f.dwmc as wtdw,DATEADD(day, 14, djrq) as yqjcrq,a.jdzt as jdzt1,
         * g.jdzt as jdzt2,e.sjdid as wtdh
         * FROM dbo.YQSF_SJMX AS a LEFT JOIN
         * dbo.YQSF_SJD as e on a.sjdid = e.id LEFT JOIN
         * dbo.YQSF_KH as f on e.khid = f.khid LEFT JOIN
         * dbo.JCXX_XHGG_BM AS b ON a.XHGGBM = b.XHGGBM LEFT JOIN
         * dbo.JCXX_ZZC_BM AS c ON b.ZZCBM = c.ZZCBM LEFT JOIN
         * dbo.JCXX_QJMC_BM AS d ON b.QJMCBM = d.QJMCBM LEFT JOIN
         * dbo.SJCL_CHYQ as g on g.id = a.id
         * where d.QJMCBM = 1000 and e.djrq > '2019-04-21'";                     // 查询searchAll
         *
         * strSQL += " and  g.jdzt is null and a.jdzt<>'检完'";                  // 待检:JDZT is null
         *
         *  if (q != "")
         *  {
         *      strSQL += " and (ccbh like '%" + q + "%' or xhggmc like '%" + q + "%'";
         *      strSQL += ")";
         *  }
         *
         *  IEnumerable<SJMX> ret = _sjmxDapperRepository.Query(strSQL);
         *  return ret;
         * }
         *
         * public async Task<PagedResultDto<SJMXListDto>> GetPagedSjmxs(GetVwSjmxsInput input)
         * {
         *  Expression<Func<SJMX, bool>> predicate = p => (p.Id != 1);
         *
         *  var totalCount = _sjmxDapperRepository.Count(predicate);
         *
         *
         *  var entityList = await _sjmxDapperRepository.GetAll()
         *      .OrderByDescending(t => t.Id)
         *      .PageBy(input)
         *      .ToListAsync();
         *  var entityListDtos = ObjectMapper.Map<List<SJMXListDto>>(entityList);
         *
         *  return new PagedResultDto<SJMXListDto>(totalCount, entityListDtos);
         * }
         */

        public PagedResultDto <SJMX> GetPagedSjmxs(GetVwSjmxsInput input)
        {
            // 数据库里面必须有 SJMX 实体或者视图
            // Expression<Func<SJMX, bool>> predicate = p => p.qjmc == "全站仪";
            Expression <Func <SJMX, bool> > predicate = p => p.Id > 0;

            if (!input.FilterText.IsNullOrWhiteSpace())
            {
                predicate = predicate.And(p => (p.xhggmc.Contains(input.FilterText) || p.ccbh.Contains(input.FilterText) || p.wtdh.Contains(input.FilterText) || p.wtdw.Contains(input.FilterText)));
            }

            var totalCount         = _sjmxDapperRepository.Count(predicate);
            IEnumerable <SJMX> ret = _sjmxDapperRepository.GetAllPaged(
                predicate,
                input.SkipCount / input.MaxResultCount,
                input.MaxResultCount,
                input.Sorting, input.Order == "desc"); // input.Order=="asc"  true/false
            List <SJMX> tempList2 = ObjectMapper.Map <List <SJMX> >(ret);

            return(new PagedResultDto <SJMX>(
                       totalCount,
                       tempList2
                       ));
        }
コード例 #9
0
ファイル: SomeDomainService.cs プロジェクト: seamusic/Stove
        public void DoSomeStuff()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                Logger.Debug("Uow Began!");

                _personRepository.Insert(new Person("Oğuzhan"));
                _personRepository.Insert(new Person("Ekmek"));

                _animalRepository.Insert(new Animal("Kuş"));
                _animalRepository.Insert(new Animal("Kedi"));

                _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                _unitOfWorkManager.Current.SaveChanges();

                Person personCache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person person = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");
                Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                #region DAPPER

                var list = new List <string>
                {
                    "elma", "armut"
                };

                ExpressionStarter <Animal> predicate = PredicateBuilder.New <Animal>();
                predicate.And(x => x.Name == "Kuş");

                IEnumerable <Animal> birdsSet = _animalDapperRepository.GetSet(new { Name = "Kuş" }, 0, 10, "Id");

                IEnumerable <Person> personFromDapper = _personDapperRepository.GetList(new { Name = "Oğuzhan" });

                IEnumerable <Animal> birdsFromExpression = _animalDapperRepository.GetSet(predicate, 0, 10, "Id");

                IEnumerable <Animal> birdsPagedFromExpression = _animalDapperRepository.GetListPaged(x => x.Name == "Kuş", 0, 10, "Name");

                IEnumerable <Person> personFromDapperExpression = _personDapperRepository.GetList(x => x.Name.Contains("Oğuzhan"));

                int birdCount = _animalDapperRepository.Count(x => x.Name == "Kuş");

                var personAnimal = _animalDapperRepository.Query <PersonAnimal>("select Name as PersonName,'Zürafa' as AnimalName from Person with(nolock) where name=@name", new { name = "Oğuzhan" })
                                   .MapTo <List <PersonAnimalDto> >();

                birdsFromExpression.ToList();
                birdsPagedFromExpression.ToList();
                birdsSet.ToList();

                IEnumerable <Person> person2FromDapper = _personDapperRepository.Query("select * from Person with(nolock) where name =@name", new { name = "Oğuzhan" });

                #endregion

                Person person2Cache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person oguzhan = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person oguzhan2 = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");

                uow.Complete();

                _messageBus.Publish <IPersonAddedMessage>(new PersonAddedMessage
                {
                    Name          = "Oğuzhan",
                    CorrelationId = NewId.NextGuid()
                });

                _hangfireBackgroundJobManager.EnqueueAsync <SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                {
                    Message = "Oğuzhan"
                });

                Logger.Debug("Uow End!");
            }
        }
コード例 #10
0
        public void DoSomeStuff()
        {
            try
            {
                using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
                {
                    Logger.Debug("Uow Began!");

                    int persionId1 = _personRepository.InsertAndGetId(new Person("Oğuzhan"));
                    _personRepository.Insert(new Person("Ekmek"));

                    int animalId1 = _animalRepository.InsertAndGetId(new Animal("Kuş"));
                    _animalRepository.Insert(new Animal("Kedi"));

                    _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                    _unitOfWorkManager.Current.SaveChanges();

                    Person personCache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    Person person = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");
                    Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                    using (StoveSession.Use(266))
                    {
                        _productDapperRepository.Insert(new Product("TShirt1"));
                        int gomlekId = _productDapperRepository.InsertAndGetId(new Product("Gomlek1"));

                        Product firstProduct           = _productDapperRepository.FirstOrDefault(x => x.Name == "TShirt1");
                        IEnumerable <Product> products = _productDapperRepository.GetAll();

                        firstProduct.Name = "Something";

                        _productDapperRepository.Update(firstProduct);

                        _mailDapperRepository.Insert(new Mail("New Product Added"));
                        Guid mailId = _mailDapperRepository.InsertAndGetId(new Mail("Second Product Added"));

                        IEnumerable <Mail> mails = _mailDapperRepository.GetAll();

                        Mail firstMail = mails.First();

                        firstMail.Subject = "Sorry wrong email!";

                        _mailDapperRepository.Update(firstMail);
                    }

                    Animal oneAnimal      = _animalDapperRepository.Get(animalId1);
                    Animal oneAnimalAsync = _animalDapperRepository.GetAsync(animalId1).Result;

                    Person onePerson      = _personDapperRepository.Get(persionId1);
                    Person onePersonAsync = _personDapperRepository.GetAsync(persionId1).Result;

                    IEnumerable <Animal> birdsSet = _animalDapperRepository.GetSet(x => x.Name == "Kuş", 0, 10, "Id");

                    using (_unitOfWorkManager.Current.DisableFilter(StoveDataFilters.SoftDelete))
                    {
                        IEnumerable <Person> personFromDapperNotFiltered = _personDapperRepository.GetAll(x => x.Name == "Oğuzhan");
                    }

                    IEnumerable <Person> personFromDapperFiltered = _personDapperRepository.GetAll(x => x.Name == "Oğuzhan");

                    IEnumerable <Animal> birdsFromExpression = _animalDapperRepository.GetSet(x => x.Name == "Kuş", 0, 10, "Id");

                    IEnumerable <Animal> birdsPagedFromExpression = _animalDapperRepository.GetAllPaged(x => x.Name == "Kuş", 0, 10, "Name");

                    IEnumerable <Person> personFromDapperExpression = _personDapperRepository.GetAll(x => x.Name.Contains("Oğuzhan"));

                    int birdCount = _animalDapperRepository.Count(x => x.Name == "Kuş");

                    var personAnimal = _animalDapperRepository.Query <PersonAnimal>("select Name as PersonName,'Zürafa' as AnimalName from Persons with(nolock) where name=@name", new { name = "Oğuzhan" })
                                       .MapTo <List <PersonAnimalDto> >();

                    birdsFromExpression.ToList();
                    birdsPagedFromExpression.ToList();
                    birdsSet.ToList();

                    IEnumerable <Person> person2FromDapper = _personDapperRepository.Query("select * from Persons with(nolock) where name =@name", new { name = "Oğuzhan" });

                    _personDapperRepository.Insert(new Person("oğuzhan2"));
                    int    id      = _personDapperRepository.InsertAndGetId(new Person("oğuzhan3"));
                    Person person3 = _personDapperRepository.Get(id);
                    person3.Name = "oğuzhan4";
                    _personDapperRepository.Update(person3);
                    _personDapperRepository.Delete(person3);

                    Person person2Cache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    //Person oguzhan = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    Person oguzhan2 = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");

                    uow.Complete();

                    _messageBus.Publish <IPersonAddedMessage>(new PersonAddedMessage
                    {
                        Name          = "Oğuzhan",
                        CorrelationId = NewId.NextGuid()
                    });

                    //_hangfireBackgroundJobManager.EnqueueAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                    //{
                    //    Message = "Oğuzhan"
                    //});

                    //_hangfireScheduleJobManager.ScheduleAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                    //{
                    //    Message = "Oğuzhan"
                    //}, Cron.Minutely());

                    Logger.Debug("Uow End!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw ex;
            }
        }
コード例 #11
0
        public int DoSomeStuff0()
        {
            string[] ints = new string[] { "1000", "1030", "1040" };
            Expression <Func <VW_SJCL_100, bool> > predicate;
            string val = "";
            ParameterExpression param = Expression.Parameter(typeof(int));

            if (ints.Length > 0)
            {
                predicate = p => p.QJMCBM == ints[0];
                //foreach (int o in ints) {}
                for (int i = 1; i < ints.Length; i++)
                {
                    val = ints[i];
                    //System.Diagnostics.Debug.WriteLine(val);
                    //predicate = predicate.Or(p => p.QJMCBM == ints[i]); //会报错的 out if ...
                    //predicate = predicate.Or(p => p.QJMCBM == val); //不报错但结果不对
                    //if (i.Equals(1)) predicate = predicate.Or(p => p.QJMCBM == ints[1]); // 数字 OK
                    //if (i == 2) predicate = predicate.Or(p => p.QJMCBM.Equals(ints[2])); // 数字 Error
                    //predicate = predicate.Or(p => p.QJMCBM.Equals(ints[i]));//会报错的 out if ...
                    //predicate = predicate.Or(p => p.QJMCBM.Equals(val));//不报错但结果不对
                    if (i == 1)
                    {
                        predicate = predicate.Or(p => p.QJMCBM.Equals(ints[1]));         // 字符 OK
                    }
                    if (i == 2)
                    {
                        predicate = predicate.Or(p => p.QJMCBM.Equals(ints[2]));
                    }
                    // ... ...
                }

                //predicate = predicate.Or(p => p.QJMCBM == ints[1]); // OK
                //predicate = predicate.Or(p => p.QJMCBM == ints[2]);
                predicate = predicate.And(p => p.JDZT == 100);
            }
            else
            {
                predicate = p => p.JDZT == 100;
            }

            var totalCount = _vwsjclDapperRepository.Count(predicate);

            System.Diagnostics.Debug.WriteLine(totalCount);

            // int 的 Equals 不能用!!! 改为 string OK
            ints = new string[] { "1000", "1030" };
            Expression <Func <VW_SJCL_100, bool> > newExp;

            if (ints.Length > 0)
            {
                ParameterExpression parameter = Expression.Parameter(typeof(VW_SJCL_100), "p");
                MemberExpression    member    = Expression.PropertyOrField(parameter, "QJMCBM");
                MethodInfo          method    = typeof(string).GetMethod("Equals", new[] { typeof(string) });
                ConstantExpression  constant  = Expression.Constant(ints[0], typeof(string));
                newExp = Expression.Lambda <Func <VW_SJCL_100, bool> >(Expression.Call(member, method, constant), parameter);
                for (int i = 1; i < ints.Length; i++)
                {
                    newExp = newExp.Or(Expression.Lambda <Func <VW_SJCL_100, bool> >(Expression.Call(member, method, Expression.Constant(ints[i], typeof(string))), parameter));
                }
                newExp = newExp.And(p => p.JDZT == 100);
            }
            else
            {
                newExp = p => p.JDZT == 100;
            }

            // 先 and 再 or 也可以
            Expression <Func <VW_SJCL_100, bool> > newExp = p => p.JDZT == 100;

            if (ints.Length > 0)
            {
                ParameterExpression parameter = Expression.Parameter(typeof(VW_SJCL_100), "p");
                MemberExpression    member    = Expression.PropertyOrField(parameter, "QJMCBM");
                MethodInfo          method    = typeof(string).GetMethod("Equals", new[] { typeof(string) });
                ConstantExpression  constant  = Expression.Constant(ints[0], typeof(string));
                newExp = newExp.And(Expression.Lambda <Func <VW_SJCL_100, bool> >(Expression.Call(member, method, constant), parameter));
                for (int i = 1; i < ints.Length; i++)
                {
                    newExp = newExp.Or(Expression.Lambda <Func <VW_SJCL_100, bool> >(Expression.Call(member, method, Expression.Constant(ints[i], typeof(string))), parameter));
                }
            }

            var totalCount2 = _vwsjclDapperRepository.Count(newExp);

            System.Diagnostics.Debug.WriteLine(totalCount2);

            //predicate = p => p.JDZT == 100;
            //predicate = predicate.And(p => p.QJMCBM == 1030);
            //totalCount = _vwsjclDapperRepository.Count(predicate);

            return(totalCount);
        }
コード例 #12
0
        /// <summary>
        /// 增加 LastLogintime,Dapper 实现
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PagedResultDto <AbpUser> GetPagedMemberUsers(PagedMemberUserResultRequestDto input)
        {
            //var sw = new Stopwatch();
            //sw.Start();

            //Expression<Func<AbpUser,Role, bool>> predicat = (p,b) => (p.TenantId == null &&  p.RoleNames );

            /*
             * _repository -> MemberUser -> 查询记录 from AbpUsers where UserType =1
             *              user -> UserType =0 也会显示,TenantId = 1 不显示,未启用租户,User 没有 LastLoginTime 的
             */

            Expression <Func <AbpUser, bool> > predicate = p => (p.TenantId == null && p.IsDeleted == false);

            //if (input.From != null) // DateTime? 会有问题
            if (input.From != null && input.From > DateTimeOffset.MinValue)
            {
                predicate = predicate.And(p => p.CreationTime >= DateTime.Parse(input.From.ToString())); // input.From
            }
            if (input.To != null && input.To > DateTimeOffset.MinValue)                                  // != null
            {
                predicate = predicate.And(p => p.CreationTime <= DateTime.Parse(input.To.ToString()));   // input.To
            }

            //if (!input.Filter.IsNullOrWhiteSpace())
            //if (!input.Keyword.IsNullOrWhiteSpace())
            //{
            //    predicate = predicate.And(p => p.Name.Contains(input.Keyword));
            //}

            if (!input.Keyword.IsNullOrWhiteSpace())
            {
                predicate = predicate.And(p => p.UserName.Contains(input.Keyword));
            }

            if (input.IsActive != null)
            {
                predicate = predicate.And(p => p.IsActive == (input.IsActive == "true"));
            }

            var totalCount            = _userRepository.Count(predicate);
            IEnumerable <AbpUser> ret = _userRepository.GetAllPaged(
                predicate,
                input.SkipCount / input.MaxResultCount,
                input.MaxResultCount,
                input.Sorting, input.Order == "asc"); // input.Order=="asc"  true/false

            List <AbpUser> tempList = ObjectMapper.Map <List <AbpUser> >(ret);

            /*
             * List<AbpUser> tempList2 = new List<AbpUser>();
             * IEnumerator<AbpUser> currentEnumerator = ret.GetEnumerator();
             * if (currentEnumerator != null)
             * {
             *  for (int count = 0; currentEnumerator.MoveNext(); count++)
             *  {
             *      //currentEnumerator.Current.RoleNames = GetRoles(currentEnumerator.Current.Id); // conn 嵌套错误,在下面处理
             *      tempList.Add(currentEnumerator.Current);
             *  }
             * }
             */

            // Abp.Dapper 不支持一对多,只能 Dapper 进行
            foreach (AbpUser o in tempList)
            {
                o.RoleNames = GetRoles(o.Id);
                //o.QJMCRoleNames = GetQJMCRoleNames(o.RoleNames); // 检定器具名称列表
            }

            //sw.Stop();
            //Logger.Error("耗时:" + sw.ElapsedMilliseconds + (sw.ElapsedMilliseconds > 1000 ? "#####" : string.Empty) + "毫秒\n"); // 可以记录操作

            return(new PagedResultDto <AbpUser>(
                       totalCount,
                       tempList
                       ));
        }
コード例 #13
0
        public int CountByAuthorId(int authorId)
        {
            var parameters = new { AuthorId = authorId };

            return(_repository.Count(parameters));
        }