public async Task <IList <PositionEntity> > Query(PositionQueryModel model)
        {
            var paging = model.Paging();

            var query = Db.Find();

            query.WhereIf(model.DepartmentId.NotEmpty(), m => m.DepartmentId == model.DepartmentId);
            query.WhereIf(model.Name.NotNull(), m => m.Name.Contains(m.Name));
            query.WhereIf(model.Code.NotNull(), m => m.Code == model.Code);

            if (!paging.OrderBy.Any())
            {
                query.OrderByDescending(m => m.Id);
            }

            var result = await query.LeftJoin <AccountEntity>((x, y) => x.CreatedBy == y.Id)
                         .LeftJoin <DepartmentEntity>((x, y, z) => x.DepartmentId == z.Id)
                         .LeftJoin <CompanyEntity>((x, y, z, m) => z.CompanyId == m.Id)
                         .Select((x, y, z, m) => new { x, DepartmentName = z.Name, CompanyName = m.Name, Creator = y.Name })
                         .PaginationAsync(paging);

            model.TotalCount = paging.TotalCount;

            return(result);
        }
Beispiel #2
0
        public async Task <IList <PositionEntity> > Query(PositionQueryModel model)
        {
            var paging = model.Paging();

            var query = Db.Find();

            query.WhereNotNull(model.Name, m => m.Name.Contains(model.Name));
            query.WhereNotNull(model.Code, m => m.Code == model.Code);

            var joinQuery = query.LeftJoin <AccountEntity>((x, y) => x.CreatedBy == y.Id);

            if (!paging.OrderBy.Any())
            {
                joinQuery.OrderByDescending((x, y) => x.Id);
            }

            joinQuery.Select((x, y) => new { x, Creator = y.Name });

            var result = await joinQuery.PaginationAsync(paging);

            model.TotalCount = paging.TotalCount;

            return(result);
        }