public async Task <QueryResult <IDictionary <string, object> > > QueryDeviceConfigDynamic( DeviceConfigQueryProjection projection, DeviceConfigQueryOptions options, DeviceConfigQueryFilter filter = null, DeviceConfigQuerySort sort = null, DeviceConfigQueryPaging paging = null) { var query = DeviceConfigs; #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 || !DeviceConfigQueryOptions.IsLoadAllAllowed)) { query = query.SelectPage(paging.page, paging.limit); } #endregion } if (options.single_only) { var single = query.SingleOrDefault(); if (single == null) { return(null); } var singleResult = GetDeviceConfigDynamic(single, projection, options); return(new QueryResult <IDictionary <string, object> >() { Single = singleResult }); } var entities = query.ToList(); var list = GetDeviceConfigDynamic(entities, projection, options); var result = new QueryResult <IDictionary <string, object> >(); result.List = list; if (options.count_total) { result.Count = totalCount; } return(result); }
public ValidationData ValidateGetDeviceConfigs( ClaimsPrincipal principal, DeviceConfigQueryFilter filter, DeviceConfigQuerySort sort, DeviceConfigQueryProjection projection, DeviceConfigQueryPaging paging, DeviceConfigQueryOptions options) { return(new ValidationData()); }
public List <IDictionary <string, object> > GetDeviceConfigDynamic( IEnumerable <DeviceConfig> rows, DeviceConfigQueryProjection projection, DeviceConfigQueryOptions options) { var list = new List <IDictionary <string, object> >(); foreach (var o in rows) { var obj = GetDeviceConfigDynamic(o, projection, options); list.Add(obj); } return(list); }
public async Task <IActionResult> Get([FromQuery][QueryObject] DeviceConfigQueryFilter filter, [FromQuery] DeviceConfigQuerySort sort, [FromQuery] DeviceConfigQueryProjection projection, [FromQuery] DeviceConfigQueryPaging paging, [FromQuery] DeviceConfigQueryOptions options) { var validationData = _service.ValidateGetDeviceConfigs( User, filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryDeviceConfigDynamic( projection, options, filter, sort, paging); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(result))); }
public IDictionary <string, object> GetDeviceConfigDynamic( DeviceConfig row, DeviceConfigQueryProjection projection, DeviceConfigQueryOptions options) { var obj = new Dictionary <string, object>(); foreach (var f in projection.GetFieldsArr()) { switch (f) { case DeviceConfigQueryProjection.INFO: { var entity = row; obj["id"] = entity.Id; obj["identifier"] = entity.Identifier; obj["is_current"] = entity.IsCurrent; obj["kafka_server"] = entity.KafkaServer; obj["kafka_username"] = entity.KafkaUsername; obj["remove_old_events_job_settings"] = entity.RemoveOldEventsJobSettings; obj["send_unsent_events_job_settings"] = entity.SendUnsentEventsJobSettings; 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" }; if (entity.NextROEJobStart != null) { time = entity.NextROEJobStart.Value .ToDefaultTimeZone(); timeStr = time.ToString(options.date_format); obj["next_roe_job_start"] = new { display = timeStr, iso = $"{time.ToUniversalTime():s}Z" }; } if (entity.NextSUEJobStart != null) { time = entity.NextSUEJobStart.Value .ToDefaultTimeZone(); timeStr = time.ToString(options.date_format); obj["next_sue_job_start"] = new { display = timeStr, iso = $"{time.ToUniversalTime():s}Z" }; } } break; } } return(obj); }