| | |
| | | var q = rep.AsQueryable().AsNoTracking(); |
| | | if (query != null) q = query(q); |
| | | else q = q.OrderBy(it => it.Sort).ThenBy(it => it.CreatedTime); |
| | | if (page.OrderInput.IsNotNull()) |
| | | q = q.CustomOrderBy(page.OrderInput); |
| | | var s = selector == null |
| | | ? q.ProjectToType<TItem>() |
| | |
| | | where TItem : class, new() |
| | | where TResult : PagedListQueryResult<TItem>, new() |
| | | { |
| | | if (page.OrderInput.IsNotNull()) |
| | | q = q.CustomOrderBy(page.OrderInput); |
| | | var pagedList = await q.ToPagedListAsync(page.Page, page.Rows, cancellationToken); |
| | | var result = new TResult(); |
| | |
| | | return Ordering(source, parameter, propertyName, "ThenByDescending"); |
| | | } |
| | | |
| | | public static async Task<TResult> GetDetail<TEntity, TResult>( |
| | | this Guid id, |
| | | CancellationToken cancellationToken = default) |
| | | where TEntity : CommonEntity, new() |
| | | { |
| | | var rep = Db.GetRepository<TEntity>(); |
| | | return await rep.AsQueryable().AsNoTracking() |
| | | .Where(it => it.Id == id) |
| | | .GetDetail<TEntity, TResult>(cancellationToken); |
| | | } |
| | | |
| | | public static async Task<TResult> GetDetail<TEntity, TResult>( |
| | | this IQueryable<TEntity> q, |
| | | CancellationToken cancellationToken = default) |
| | | { |
| | | var model = await q |
| | | .ProjectToType<TResult>() |
| | | .FirstOrDefaultAsync(cancellationToken); |
| | | if (model == null) |
| | | { |
| | | var summary = await typeof(TEntity).GetSummary(); |
| | | throw Oops.Oh(EnumErrorCodeType.s404, $"该{summary ?? "信息"}"); |
| | | } |
| | | return model; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置是否禁用 |
| | | /// </summary> |
| | |
| | | : 0; |
| | | } |
| | | |
| | | public static async Task<Guid> UpdateData<TEntity, TRequest>( |
| | | this IQueryable<TEntity> q, |
| | | TRequest request, |
| | | Action<TEntity> update = null, |
| | | CancellationToken cancellationToken = default) |
| | | where TEntity : CommonEntity, new() |
| | | { |
| | | var rep = Db.GetRepository<TEntity>(); |
| | | var entity = await q.FirstOrDefaultAsync(); |
| | | if (entity == null) |
| | | { |
| | | var summary = await typeof(TEntity).GetSummary(); |
| | | throw Oops.Oh(EnumErrorCodeType.s404, $"该{summary ?? "信息"}"); |
| | | } |
| | | |
| | | if (update != null) update(entity); |
| | | else request.Adapt(entity); |
| | | await rep.UpdateAsync(entity); |
| | | return entity.Id; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存数据 |
| | | /// </summary> |