예제 #1
0
파일: JobService.cs 프로젝트: nrcc/Berry
        /// <summary>
        /// 职位列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns></returns>
        public IEnumerable <RoleEntity> GetPageList(PaginationEntity pagination, string queryJson)
        {
            var     expression = LambdaExtension.True <RoleEntity>();
            JObject queryParam = queryJson.TryToJObject();

            if (queryParam != null)
            {
                //机构主键
                if (!queryParam["organizeId"].IsEmpty())
                {
                    string organizeId = queryParam["organizeId"].ToString();
                    expression = expression.And(t => t.OrganizeId == organizeId);
                }
                //查询条件
                if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                {
                    string condition = queryParam["condition"].ToString();
                    string keyword   = queryParam["keyword"].ToString();
                    switch (condition)
                    {
                    case "EnCode":                //职位编号
                        expression = expression.And(t => t.EnCode.Contains(keyword));
                        break;

                    case "FullName":              //职位名称
                        expression = expression.And(t => t.FullName.Contains(keyword));
                        break;
                    }
                }
            }

            expression = expression.And(t => t.Category == 3);
            return(this.BaseRepository().FindList <RoleEntity>(expression, pagination));
        }
예제 #2
0
        public PaginationDTO <CommentDTO> GetCommentPaginationOfPostWithPreservedFetch(string postId, DateTime createdDate, int pageSize)
        {
            PaginationEntity <CommentEntity> commentPaginationEntity = commentRepository.GetCommentPaginationOfPostWithPreservedFetch(postId, createdDate, pageSize);
            PaginationDTO <CommentDTO>       commentPaginationDTO    = dataMapper.MapCommentPaginationEntityToDTO(commentPaginationEntity);

            return(commentPaginationDTO);
        }
예제 #3
0
        public PaginationDTO <CommentDTO> GetCommentPagination(int pageNumber, int pageSize, string postId = null, string commentId = null, string searchQuery = null)
        {
            PaginationEntity <CommentEntity> commentPaginationEntity = commentRepository.GetCommentPagination(pageNumber, pageSize, postId, commentId, searchQuery);
            PaginationDTO <CommentDTO>       commentPaginationDTO    = dataMapper.MapCommentPaginationEntityToDTO(commentPaginationEntity);

            return(commentPaginationDTO);
        }
예제 #4
0
        /// <summary>
        /// 用户组列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns></returns>
        public IEnumerable <RoleEntity> GetPageList(PaginationEntity pagination, string queryJson)
        {
            var     expression = LambdaExtension.True <RoleEntity>();
            JObject queryParam = queryJson.TryToJObject();

            if (queryParam != null)
            {
                string enCode   = queryParam["EnCode"].ToString();
                string fullName = queryParam["FullName"].ToString();

                if (!string.IsNullOrEmpty(enCode))
                {
                    expression = expression.And(t => t.EnCode.Contains(enCode));
                }

                if (!string.IsNullOrEmpty(fullName))
                {
                    expression = expression.And(t => t.FullName.Contains(fullName));
                }
            }
            expression = expression.And(t => t.Category == 4 && t.DeleteMark == false && t.EnabledMark == true);

            IEnumerable <RoleEntity> res = this.BaseRepository().FindList <RoleEntity>(expression, pagination);

            return(res);
        }
        public ActionResult Index(string searchTerm, int page = 1)
        {
            searchTerm = StringManipulation.CapitalizeName(searchTerm);
            string result;

            if (string.IsNullOrEmpty(searchTerm))
            {
                result = _foodAppService.GetAllPaginated(page, 20);
            }
            else
            {
                ICollection <QueryFilter> filters = new List <QueryFilter>();
                QueryFilter filter = new QueryFilter("Name", searchTerm, Operator.StartsWith);
                filters.Add(filter);

                result = _foodAppService.FindPaginated(filters, page, 20);
            }

            PaginationEntity <FoodVm> foodsPaginated = string.IsNullOrEmpty(result)
                ? new PaginationEntity <FoodVm>()
                : JsonConvert.DeserializeObject <PaginationEntity <FoodVm> >(result);

            SerializablePagedList <FoodVm> list    = new SerializablePagedList <FoodVm>(foodsPaginated.Items, page, 20, foodsPaginated.MetaData.TotalItemCount);
            IPagedList <FoodVm>            foodVms = list;

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_foodTable", foodVms));
            }
            return(View(foodVms));
        }
예제 #6
0
        /// <summary>
        /// 获取分页数据(管理页面调用)
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="queryJson"></param>
        /// <returns></returns>
        public DataTable GetPageList(PaginationEntity pagination, string queryJson)
        {
            DataTable      res  = null;
            IDbTransaction tran = null;

            this.Logger(this.GetType(), "获取所有功能按钮-GetModuleButtonList", () =>
            {
                using (var conn = this.BaseRepository().GetBaseConnection())
                {
                    tran = conn.BeginTransaction();

                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(@"SELECT
	                                m.Id,
	                                m.ModuleId,
	                                m1.FullName as ModuleName,
	                                m.EnCode,
	                                m.FullName,
	                                m.SortCode,
	                                m.DeleteMark,
	                                m.EnabledMark,
	                                m.Description,
	                                m.CreateDate,
	                                m.CreateUserId,
	                                m.CreateUserName,
	                                m.ModifyDate,
	                                m.ModifyUserId,
	                                m.ModifyUserName
                                FROM
	                                Base_ModuleForm m
                                LEFT JOIN Base_Module m1 ON m1.Id = m.ModuleId
                                WHERE m.DeleteMark = 0");

                    List <DbParameter> parameter = new List <DbParameter>();
                    JObject queryParam           = queryJson.TryToJObject();
                    if (queryParam != null)
                    {
                        if (!string.IsNullOrEmpty(queryParam["Keyword"].ToString()))//关键字查询
                        {
                            string keyord = queryParam["Keyword"].ToString();
                            strSql.Append(@" AND ( m1.FullName LIKE @keyword 
                                        or m.FullName LIKE @keyword 
                                        or m.CreateUserName LIKE @keyword )");

                            parameter.Add(DbParameters.CreateDbParameter("@keyword", '%' + keyord + '%'));
                        }
                    }

                    Tuple <DataTable, int> data = this.BaseRepository().FindTable(conn, strSql.ToString(), parameter, pagination.sidx, pagination.sord.ToLower() == "asc", pagination.rows, pagination.page);
                    pagination.records          = data.Item2;

                    tran.Commit();
                }
            }, e =>
            {
                Trace.WriteLine(e.Message);
            });

            return(res);
        }
예제 #7
0
파일: NewsService.cs 프로젝트: nrcc/Berry
        /// <summary>
        /// 新闻列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns></returns>
        public IEnumerable <NewsEntity> GetPageList(PaginationEntity pagination, string queryJson)
        {
            var     expression = LambdaExtension.True <NewsEntity>();
            JObject queryParam = queryJson.TryToJObject();

            if (queryParam != null)
            {
                if (!queryParam["FullHead"].IsEmpty())
                {
                    string FullHead = queryParam["FullHead"].ToString();
                    expression = expression.And(t => t.FullHead.Contains(FullHead));
                }
                if (!queryParam["Category"].IsEmpty())
                {
                    string Category = queryParam["Category"].ToString();
                    expression = expression.And(t => t.Category == Category);
                }
                if (!queryParam["CategoryId"].IsEmpty())
                {
                    string CategoryId = queryParam["CategoryId"].ToString();
                    expression = expression.And(t => t.CategoryId == CategoryId);
                }
            }

            expression = expression.And(t => t.TypeId == 1);
            return(this.BaseRepository().FindList(expression, pagination));
        }
예제 #8
0
        public PaginationEntity <FullUserInfo> Query(UserQueryForm form)
        {
            PaginationEntity <FullUserInfo> result = new PaginationEntity <FullUserInfo>();
            var                mapper  = Common.GetMapper();
            UserDao            userdao = new UserDao(mapper);
            User_BoardGroupDao ubdao   = new User_BoardGroupDao(mapper);
            BoardGroupDao      bgdao   = new BoardGroupDao(mapper);
            var                users   = userdao.Query(form);
            var                userids = (from u in users
                                          select u.ID).ToList();
            var ubs = ubdao.Query(new User_BoardGroupQueryForm {
                UserIDs = userids
            });
            var allboards = bgdao.Query(new BoardGroupQueryForm {
                Enabled = true
            });
            List <FullUserInfo> list = new List <FullUserInfo>();

            users.ForEach(u =>
            {
                var boards = (from ub in ubs
                              join b in allboards on ub.BoardGroupID equals b.ID
                              where ub.UserID == u.ID
                              select b).ToList();
                var fulluser = new FullUserInfo();
                u.CopyTo <FullUserInfo>(fulluser);
                fulluser.Boards = boards;
                list.Add(fulluser);
            });
            result.RecordCount = form.RecordCount;
            result.List        = list;
            return(result);
        }
예제 #9
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns>返回分页列表</returns>
        public IEnumerable <UserDemandEntity> GetPageList(PaginationEntity pagination, string queryJson)
        {
            var     expression = LambdaExtension.True <UserDemandEntity>();
            JObject queryParam = queryJson.TryToJObject();

            if (queryParam != null)
            {
                if (!queryParam["Title"].IsEmpty())
                {
                    string Title = queryParam["Title"].ToString();
                    expression = expression.And(t => t.Title.Contains(Title));
                }
                if (!queryParam["CategoryId"].IsEmpty())
                {
                    string CategoryId = queryParam["CategoryId"].ToString();
                    expression = expression.And(t => t.CategoryId == CategoryId);
                }
            }

            if (OperatorProvider.Provider.Current().IsSystem)
            {
                expression = expression.And(t => t.IsDelete == false);
            }
            else
            {
                expression = expression.And(t => t.IsDelete == false && t.CreateUserId == OperatorProvider.Provider.Current().UserId);
            }
            return(this.BaseRepository().FindList <UserDemandEntity>(expression, pagination));
        }
예제 #10
0
        public PaginationEntity <PostEntity> GetPostPagination(int pageNumber, int pageSize, string category = null, string searchQuery = null)
        {
            try
            {
                IQueryable <PostEntity> postQueryable = Context.PostEntities
                                                        .Include(x => x.PostCategory);

                if (category != null)
                {
                    postQueryable = postQueryable
                                    .Where(x => x.PostCategory.Name.Equals(category));
                }

                if (searchQuery != null)
                {
                    string encodedSearchQuery = HttpUtility.HtmlEncode(searchQuery);

                    postQueryable = postQueryable
                                    .Where(x => x.Title.Contains(encodedSearchQuery) ||
                                           x.ShortDescription.Contains(encodedSearchQuery) ||
                                           x.PostCategory.Name.Contains(encodedSearchQuery));
                }

                Expression <Func <PostEntity, DateTime> > postOrderByExpression = (x => x.CreatedDate);
                PaginationEntity <PostEntity>             postPaginationEntity  = GetPaginationEntity(postQueryable, isDesc: true, postOrderByExpression, pageNumber, pageSize);

                return(postPaginationEntity);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #11
0
파일: PostService.cs 프로젝트: dashluu/Blog
        public PaginationDTO <PostCardDTO> GetPostCardPagination(int pageNumber, int pageSize, string category = null, string searchQuery = null)
        {
            PaginationEntity <PostEntity> postPaginationEntity  = postRepository.GetPostPagination(pageNumber, pageSize, category, searchQuery);
            PaginationDTO <PostCardDTO>   postCardPaginationDTO = dataMapper.MapPostCardPaginationEntityToDTO(postPaginationEntity);

            return(postCardPaginationDTO);
        }
예제 #12
0
        public PostEntityWithPaginatedComments GetPostWithPaginatedComments(string id, int pageSize)
        {
            try
            {
                PostEntity postEntity = Context.PostEntities
                                        .AsNoTracking()
                                        .Where(x => x.PostId.Equals(id))
                                        .Include(x => x.PostCategory)
                                        .First();

                PaginationEntity <CommentEntity> commentPaginationEntity = commentRepository.GetCommentPaginationOfPostWithPreservedFetch(postId: id, createdDate: DateTime.Now, pageSize);

                PostEntityWithPaginatedComments postEntityWithPaginatedComments = new PostEntityWithPaginatedComments()
                {
                    Post = postEntity,
                    CommentPaginationEntity = commentPaginationEntity
                };

                return(postEntityWithPaginatedComments);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #13
0
        public List <PaginationEntity <PostEntity> > GetPostPaginationList(int pageSize, string searchQuery = null)
        {
            try
            {
                List <CategoryEntity> categoryEntities = Context.CategoryEntities.ToList();
                List <PaginationEntity <PostEntity> > postPaginationEntities = new List <PaginationEntity <PostEntity> >();

                foreach (CategoryEntity categoryEntity in categoryEntities)
                {
                    PaginationEntity <PostEntity> postPaginationEntity = GetPostPagination(pageNumber: 1, pageSize, category: categoryEntity.Name, searchQuery);

                    if (postPaginationEntity == null || postPaginationEntity.Entities == null || postPaginationEntity.Pages == 0)
                    {
                        continue;
                    }

                    postPaginationEntities.Add(postPaginationEntity);
                }

                return(postPaginationEntities);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #14
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="orderby">排序条件</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public IEnumerable <T> FindPageList(Expression <Func <T, bool> > orderby, PaginationEntity pagination)
        {
            if (pagination == null)
            {
                pagination = new PaginationEntity
                {
                    PageSize  = 20,
                    PageIndex = 1
                };
            }

            bool isAsc     = pagination.Sord.ToLower().Equals("asc");
            int  pageSize  = pagination.PageSize;
            int  pageIndex = pagination.PageIndex;

            IEnumerable <T> res;

            IQuery <T> query = _context.Query <T>();

            if (isAsc)
            {
                res = query.OrderBy(orderby).TakePage(pageIndex, pageSize).ToList();
            }
            else
            {
                res = query.OrderByDesc(orderby).TakePage(pageIndex, pageSize).ToList();
            }
            int total = query.Count();

            pagination.TotalRecords = total;

            return(res);
        }
예제 #15
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns>返回分页列表</returns>
        public IEnumerable <WechatConfigEntity> GetPageList(PaginationEntity pagination, string queryJson)
        {
            IEnumerable <WechatConfigEntity> res = null;
            IDbTransaction tran = null;

            Logger(this.GetType(), "GetPageList-获取列表", () =>
            {
                using (var conn = this.BaseRepository().GetBaseConnection())
                {
                    tran = conn.BeginTransaction();

                    var expression     = LambdaExtension.True <WechatConfigEntity>();
                    JObject queryParam = queryJson.TryToJObject();
                    if (queryParam != null)
                    {
                        if (!queryParam["AppSecret"].IsEmpty())
                        {
                            string AppSecret = queryParam["AppSecret"].ToString();
                            expression       = expression.And(t => t.AppSecret.Contains(AppSecret));
                        }
                    }
                    expression = expression.And(c => c.DeleteMark == false);
                    Tuple <IEnumerable <WechatConfigEntity>, int> tuple = this.BaseRepository().FindList <WechatConfigEntity>(conn, expression, pagination.sidx, pagination.sord.ToLower() == "asc", pagination.rows, pagination.page, tran);
                    pagination.records = tuple.Item2;
                    res = tuple.Item1;

                    tran.Commit();
                }
            }, e =>
            {
                Trace.WriteLine(e.Message);
            });
            return(res);
        }
예제 #16
0
        public PaginationEntity <CommentEntity> GetCommentPagination(int pageNumber, int pageSize, string postId = null, string commentId = null, string searchQuery = null)
        {
            try
            {
                Expression <Func <CommentEntity, DateTime> > commentOrderByExpression = (x => x.CreatedDate);
                IQueryable <CommentEntity> commentQueryable = Context.CommentEntities.AsQueryable();

                if (postId != null)
                {
                    commentQueryable = commentQueryable
                                       .Where(x => x.Post.PostId.Equals(postId));
                }

                if (commentId != null)
                {
                    commentQueryable = commentQueryable
                                       .Where(x => x.ParentComment.CommentId.Equals(commentId));
                }

                if (searchQuery != null)
                {
                    commentQueryable = commentQueryable
                                       .Where(x => x.Username.Contains(searchQuery) ||
                                              x.Content.Contains(searchQuery));
                }

                PaginationEntity <CommentEntity> commentPaginationEntity = GetPaginationEntity(commentQueryable, isDesc: true, commentOrderByExpression, pageNumber, pageSize);

                return(commentPaginationEntity);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #17
0
파일: Repository.T.cs 프로젝트: nrcc/Berry
        /// <summary>
        /// 根据分页参数获取一条数据,返回对象集合
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public IEnumerable <T> FindList(PaginationEntity pagination)
        {
            int total = pagination.records;
            var data  = _db.FindList <T>(pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);

            pagination.records = total;
            return(data);
        }
예제 #18
0
        /// <summary>
        /// 根据条件获取分页数据
        /// </summary>
        /// <typeparam name="T">动态对象</typeparam>
        /// <param name="condition">筛选条件</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public IEnumerable <T> FindList <T>(Expression <Func <T, bool> > condition, PaginationEntity pagination) where T : IEntity, new()
        {
            int total = pagination.records;
            var data  = _db.FindList <T>(condition, pagination.sidx, pagination.sord.ToLower() == "asc", pagination.rows, pagination.page, out total);

            pagination.records = total;
            return(data);
        }
예제 #19
0
        /// <summary>
        /// 获取分页DataTable
        /// </summary>
        /// <param name="strSql">T-SQL语句</param>
        /// <param name="parameters">参数</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public DataTable FindTable(string strSql, object parameters, PaginationEntity pagination)
        {
            int total = pagination.records;
            var data  = _db.FindTable(strSql, parameters, pagination.sidx, pagination.sord.ToLower() == "asc", pagination.rows, pagination.page, out total);

            pagination.records = total;
            return(data);
        }
예제 #20
0
        /// <summary>
        /// 返回DataTable
        /// </summary>
        /// <param name="strSql">T-SQL语句</param>
        /// <param name="dbParameter">DbCommand参数</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public DataTable FindTable(string strSql, DbParameter[] dbParameter, PaginationEntity pagination)
        {
            int total = pagination.records;
            var data  = _db.FindTable(strSql, dbParameter, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);

            pagination.records = total;
            return(data);
        }
예제 #21
0
        /// <summary>
        /// 执行sql语句,得到一个集合
        /// </summary>
        /// <typeparam name="T">动态对象</typeparam>
        /// <param name="strSql">T-SQL语句</param>
        /// <param name="parameters">参数</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public IEnumerable <T> FindList <T>(string strSql, object parameters, PaginationEntity pagination) where T : IEntity, new()
        {
            int total = pagination.records;
            var data  = _db.FindList <T>(strSql, parameters, pagination.sidx, pagination.sord.ToLower() == "asc", pagination.rows, pagination.page, out total);

            pagination.records = total;
            return(data);
        }
예제 #22
0
        /// <summary>
        /// 根据分页参数获取一条数据,返回对象集合
        /// </summary>
        /// <param name="strSql">T-SQL语句</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public IEnumerable <T> FindList <T>(string strSql, PaginationEntity pagination) where T : class, new()
        {
            int total = pagination.records;
            var data  = _db.FindList <T>(strSql, pagination.sidx, pagination.sord.ToLower() == "asc" ? true : false, pagination.rows, pagination.page, out total);

            pagination.records = total;
            return(data);
        }
예제 #23
0
        /// <summary>
        /// 获取与某用户的消息列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="sendId">发送人Id</param>
        /// <returns></returns>
        public List <ChatMessageDTO> GetMsgList(PaginationEntity pagination, string sendId)
        {
            //业务系统用户ID
            string userId = ClientQueryString["userId"];

            //TODO 查询数据库,获取消息列表并返回,无需推送数据,前端主动获取

            throw new NotImplementedException();
        }
예제 #24
0
        public PaginationEntity <FullReplyInfo> GetReplyList(QueryNotifyReplyForm form)
        {
            PaginationEntity <FullReplyInfo> result = new PaginationEntity <FullReplyInfo>();
            var      mapper = Common.GetMapper();
            ReplyDao dao    = new ReplyDao(mapper);

            result.List        = dao.QueryNotifyReply(form);
            result.RecordCount = form.RecordCount;
            return(result);
        }
예제 #25
0
        public PaginationEntity <FullTopicInfo> GetMyFullTopicList(TopicQueryForm form)
        {
            var      mapper   = Common.GetMapper();
            var      paging   = new PaginationEntity <FullTopicInfo>();
            TopicDao topicdao = new TopicDao(mapper);
            var      topics   = topicdao.QueryFullTopicInfo(form);

            paging.List        = topics;
            paging.RecordCount = form.RecordCount;
            return(paging);
        }
 private static async Task ValidateDataFields(SearchAccountsReq request)
 {
     try
     {
         PaginationEntity.Validate(request.Pagination);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #27
0
파일: JobService.cs 프로젝트: wyh0395/Berry
        /// <summary>
        /// 职位列表
        /// </summary>
        /// <param name="pagination">分页</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns></returns>
        public IEnumerable <RoleEntity> GetPageList(PaginationEntity pagination, string queryJson)
        {
            IEnumerable <RoleEntity> res  = null;
            IDbTransaction           tran = null;

            Logger(this.GetType(), "GetPageList-职位列表", () =>
            {
                using (var conn = this.BaseRepository().GetBaseConnection())
                {
                    tran = conn.BeginTransaction();

                    var expression     = LambdaExtension.True <RoleEntity>();
                    JObject queryParam = queryJson.TryToJObject();
                    if (queryParam != null)
                    {
                        //机构主键
                        if (!queryParam["organizeId"].IsEmpty())
                        {
                            string organizeId = queryParam["organizeId"].ToString();
                            expression        = expression.And(t => t.OrganizeId == organizeId);
                        }
                        //查询条件
                        if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                        {
                            string condition = queryParam["condition"].ToString();
                            string keyword   = queryParam["keyword"].ToString();
                            switch (condition)
                            {
                            case "EnCode":                //职位编号
                                expression = expression.And(t => t.EnCode.Contains(keyword));
                                break;

                            case "FullName":              //职位名称
                                expression = expression.And(t => t.FullName.Contains(keyword));
                                break;
                            }
                        }
                    }

                    expression = expression.And(t => t.Category == 3);
                    Tuple <IEnumerable <RoleEntity>, int> tuple = this.BaseRepository().FindList <RoleEntity>(conn, expression, pagination.sidx, pagination.sord.ToLower() == "asc", pagination.rows, pagination.page, tran);
                    pagination.records = tuple.Item2;
                    res = tuple.Item1;

                    tran.Commit();
                }
            }, e =>
            {
                Trace.WriteLine(e.Message);
            });
            return(res);
        }
예제 #28
0
        public PaginationEntity <T> GetPaginationEntity <TKey>
            (IQueryable <T> queryable, bool isDesc,
            Expression <Func <T, TKey> > orderByExpression,
            int pageNumber, int pageSize)
        {
            try
            {
                List <T> entities = null;
                int      count    = queryable.Count();
                int      pages    = (int)(Math.Ceiling((double)count / pageSize));

                if (isDesc)
                {
                    queryable = queryable.OrderByDescending(orderByExpression);
                }
                else
                {
                    queryable = queryable.OrderBy(orderByExpression);
                }

                if (pageNumber > pages)
                {
                    pageNumber = pages;
                }

                if (pageNumber <= 0)
                {
                    pageNumber = 1;
                }

                int skip = (pageNumber - 1) * pageSize;

                entities = queryable.AsNoTracking().Skip(skip).Take(pageSize).ToList();

                PaginationEntity <T> paginationEntity = new PaginationEntity <T>()
                {
                    Entities    = entities,
                    Pages       = pages,
                    PageNumber  = pageNumber,
                    PageSize    = pageSize,
                    HasNext     = (skip + pageSize) < count,
                    HasPrevious = skip > 0
                };

                return(paginationEntity);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #29
0
        public async Task <PaginationEntity <TDocument> > PaginationByFilter(PaginationEntity <TDocument> pagination)
        {
            var sort = Builders <TDocument> .Sort.Ascending(pagination.Sort);

            if (pagination.SortDirection == "desc")
            {
                sort = Builders <TDocument> .Sort.Descending(pagination.Sort);
            }


            var totalDocuments = 0;

            if (pagination.FilterValue == null)
            {
                pagination.Data = await _collection.Find(p => true)
                                  .Sort(sort)
                                  .Skip((pagination.Page - 1) * pagination.PageSize)
                                  .Limit(pagination.PageSize)
                                  .ToListAsync();


                totalDocuments = (await _collection.Find(p => true).ToListAsync()).Count();
            }
            else
            {
                var valueFilter = ".*" + pagination.FilterValue.Valor + ".*";
                var filter      = Builders <TDocument> .Filter.Regex(pagination.FilterValue.Propiedad, new BsonRegularExpression(valueFilter, "i"));

                pagination.Data = await _collection.Find(filter)
                                  .Sort(sort)
                                  .Skip((pagination.Page - 1) * pagination.PageSize)
                                  .Limit(pagination.PageSize)
                                  .ToListAsync();

                totalDocuments = (await _collection.Find(filter).ToListAsync()).Count();
            }
            //libro = 1000
            //long totalDocuments = await _collection.CountDocumentsAsync(FilterDefinition<TDocument>.Empty);

            ///libro = 56

            var rounded = Math.Ceiling(totalDocuments / Convert.ToDecimal(pagination.PageSize));

            var totalPages = Convert.ToInt32(rounded);

            pagination.PagesQuantity = totalPages;
            pagination.TotalRows     = Convert.ToInt32(totalDocuments);


            return(pagination);
        }
예제 #30
0
        /// <summary>
        /// Metodo encargado de la paginacion respecto a la data obtenida. con expresion regular, para cualquier tipo de filtro.
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public async Task <PaginationEntity <TDocument> > PaginationByFilter(PaginationEntity <TDocument> pagination)
        {
            var sort = Builders <TDocument> .Sort.Ascending(pagination.Sort);

            if (pagination.SortDirection.Equals("desc"))
            {
                sort = Builders <TDocument> .Sort.Descending(pagination.Sort);
            }
            // si no tengo filtros devulevo la data
            var totalDocument = 0;

            if (pagination.FilterValue == null)//(pagination.FilterValue.Equals(null))
            {
                pagination.Data = await _collection.Find(a => true)
                                  .Sort(sort)
                                  .Skip((pagination.Page - 1) * pagination.PageSize) //desde que psosicion quiero contar
                                  .Limit(pagination.PageSize)                        //cuanto elementos quiero extraer
                                  .ToListAsync();

                totalDocument = (await _collection.Find(a => true).ToListAsync()).Count;
            }
            else
            {
                //se crea un regular expresion busca todos los valores que coincidan con una parte de busqueda del parametro
                var filterValue = ".*" + pagination.FilterValue.Valor + ".*";
                // recordar que la expresion regular del filtro debe ser agragada a la busqueda en MongoDb, no quiero que se key sensitive (letra i en l asobrecarga del metoso)
                var filter = Builders <TDocument> .Filter.Regex(pagination.FilterValue.Propiedad, new BsonRegularExpression(filterValue, "i"));

                pagination.Data = await _collection.Find(filter)
                                  .Sort(sort)
                                  .Skip((pagination.Page - 1) * pagination.PageSize) //desde que psosicion quiero contar
                                  .Limit(pagination.PageSize)                        //cuanto elementos quiero extraer
                                  .ToListAsync();

                totalDocument = (await _collection.Find(filter).ToListAsync()).Count;
            }

            //long totalDocument = await _collection.CountDocumentsAsync(FilterDefinition<TDocument>.Empty);//obtener todos los records de esta coleccion

            var redondeo = Math.Ceiling(totalDocument / Convert.ToDecimal(pagination.PageSize));


            var totalPages = (int)(redondeo); //Convert.ToInt32(redondeo);

            pagination.PageQuantity = totalPages;
            pagination.TotalRows    = (int)totalDocument;

            return(pagination);
        }