public async Task <QueryResult <IDictionary <string, object> > > QueryProductionLineDynamic( ProductionLineQueryProjection projection, ProductionLineQueryOptions options, ProductionLineQueryFilter filter = null, ProductionLineQuerySort sort = null, ProductionLineQueryPaging paging = null) { var query = ProductionLines; #region General if (filter != null) { query = query.Filter(filter); } query = query.Project(projection); int?totalCount = null; if (options.count_total) { totalCount = query.Count(); } #endregion if (!options.single_only) { #region List query if (sort != null) { query = query.Sort(sort); } if (paging != null && (!options.load_all || !ProductionLineQueryOptions.IsLoadAllAllowed)) { query = query.SelectPage(paging.page, paging.limit); } #endregion } if (options.single_only) { var single = query.SingleOrDefault(); if (single == null) { return(null); } var singleResult = GetProductionLineDynamic(single, projection, options); return(new QueryResult <IDictionary <string, object> >() { Single = singleResult }); } var entities = query.ToList(); var list = GetProductionLineDynamic(entities, projection, options); var result = new QueryResult <IDictionary <string, object> >(); result.List = list; if (options.count_total) { result.Count = totalCount; } return(result); }
public ValidationData ValidateGetProductionLines( ClaimsPrincipal principal, ProductionLineQueryFilter filter, ProductionLineQuerySort sort, ProductionLineQueryProjection projection, ProductionLineQueryPaging paging, ProductionLineQueryOptions options) { return(new ValidationData()); }
public List <IDictionary <string, object> > GetProductionLineDynamic( IEnumerable <ProductionLine> rows, ProductionLineQueryProjection projection, ProductionLineQueryOptions options) { var list = new List <IDictionary <string, object> >(); foreach (var o in rows) { var obj = GetProductionLineDynamic(o, projection, options); list.Add(obj); } return(list); }
public static IQueryable <ProductionLine> Project( this IQueryable <ProductionLine> query, ProductionLineQueryProjection projection) { foreach (var f in projection.GetFieldsArr()) { if (ProductionLineQueryProjection.MAPS.ContainsKey(f)) { foreach (var prop in ProductionLineQueryProjection.MAPS[f]) { query = query.Include(prop); } } } return(query); }
public IDictionary <string, object> GetProductionLineDynamic( ProductionLine row, ProductionLineQueryProjection projection, ProductionLineQueryOptions options) { var obj = new Dictionary <string, object>(); foreach (var f in projection.GetFieldsArr()) { switch (f) { case ProductionLineQueryProjection.INFO: { var entity = row; obj["id"] = entity.Id; obj["code"] = entity.Code; obj["info"] = entity.Info; var time = entity.CreatedTime .ToDefaultTimeZone(); var timeStr = time.ToString(options.date_format); obj["created_time"] = new { display = timeStr, iso = $"{time.ToUniversalTime():s}Z" }; time = entity.LastUpdated .ToDefaultTimeZone(); timeStr = time.ToString(options.date_format); obj["last_updated"] = new { display = timeStr, iso = $"{time.ToUniversalTime():s}Z" }; obj["disabled"] = entity.Disabled; } break; case ProductionLineQueryProjection.SELECT: { var entity = row; obj["id"] = entity.Id; obj["code"] = entity.Code; obj["disabled"] = entity.Disabled; } break; } } return(obj); }
public async Task <IActionResult> Get([FromQuery][QueryObject] ProductionLineQueryFilter filter, [FromQuery] ProductionLineQuerySort sort, [FromQuery] ProductionLineQueryProjection projection, [FromQuery] ProductionLineQueryPaging paging, [FromQuery] ProductionLineQueryOptions options) { var validationData = _service.ValidateGetProductionLines( User, filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryProductionLineDynamic( projection, options, filter, sort, paging); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(result))); }