public async Task <QueryResult <IDictionary <string, object> > > QueryProductionBatchDynamic( ProductionBatchQueryProjection projection, ProductionBatchQueryOptions options, ProductionBatchQueryFilter filter = null, ProductionBatchQuerySort sort = null, ProductionBatchQueryPaging paging = null) { var query = ProductionBatchs; #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 || !ProductionBatchQueryOptions.IsLoadAllAllowed)) { query = query.SelectPage(paging.page, paging.limit); } #endregion } if (options.single_only) { var single = query.SingleOrDefault(); if (single == null) { return(null); } var singleResult = GetProductionBatchDynamic(single, projection, options); return(new QueryResult <IDictionary <string, object> >() { Single = singleResult }); } var entities = query.ToList(); var list = GetProductionBatchDynamic(entities, projection, options); var result = new QueryResult <IDictionary <string, object> >(); result.List = list; if (options.count_total) { result.Count = totalCount; } return(result); }
public ValidationData ValidateGetProductionBatchs( ClaimsPrincipal principal, ProductionBatchQueryFilter filter, ProductionBatchQuerySort sort, ProductionBatchQueryProjection projection, ProductionBatchQueryPaging paging, ProductionBatchQueryOptions options) { return(new ValidationData()); }
public List <IDictionary <string, object> > GetProductionBatchDynamic( IEnumerable <ProductionBatch> rows, ProductionBatchQueryProjection projection, ProductionBatchQueryOptions options) { var list = new List <IDictionary <string, object> >(); foreach (var o in rows) { var obj = GetProductionBatchDynamic(o, projection, options); list.Add(obj); } return(list); }
public async Task <IActionResult> Get([FromQuery][QueryObject] ProductionBatchQueryFilter filter, [FromQuery] ProductionBatchQuerySort sort, [FromQuery] ProductionBatchQueryProjection projection, [FromQuery] ProductionBatchQueryPaging paging, [FromQuery] ProductionBatchQueryOptions options) { var validationData = _service.ValidateGetProductionBatchs( User, filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryProductionBatchDynamic( projection, options, filter, sort, paging); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(result))); }
public IDictionary <string, object> GetProductionBatchDynamic( ProductionBatch row, ProductionBatchQueryProjection projection, ProductionBatchQueryOptions options) { var obj = new Dictionary <string, object>(); foreach (var f in projection.GetFieldsArr()) { switch (f) { case ProductionBatchQueryProjection.INFO: { var entity = row; obj["id"] = entity.Id; obj["code"] = entity.Code; obj["info"] = entity.Info; obj["total_amount"] = entity.TotalAmount; obj["production_line_id"] = entity.ProductionLineId; obj["product_model_id"] = entity.ProductModelId; 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["status"] = entity.Status; obj["status_display"] = entity.Status.DisplayName(); } break; case ProductionBatchQueryProjection.P_LINE: { var entity = row.Line; if (entity != null) { obj["production_line"] = new { id = entity.Id, code = entity.Code, disabled = entity.Disabled } } ; } break; case ProductionBatchQueryProjection.P_MODEL: { var entity = row.Model; if (entity != null) { obj["product_model"] = new { id = entity.Id, code = entity.Code, name = entity.Name, } } ; } break; case ProductionBatchQueryProjection.SELECT: { var entity = row; obj["id"] = entity.Id; obj["code"] = entity.Code; } break; } } return(obj); }