Esempio n. 1
0
        public async Task <IActionResult> GetGlobals()
        {
            var cropTypes = await _db.CropTypes.ToArrayAsync();

            var parameters = await _db.Parameters.ToArrayAsync();

            var placements = await _db.Placements.ToArrayAsync();

            var subSystems = await _db.Subsystems.ToArrayAsync();

            var sensorTypes = await _db.SensorTypes.ToArrayAsync();

            var globals = new SyncData(cropTypes, parameters, placements, subSystems, sensorTypes);

            return(new JsonResult(globals));
        }
Esempio n. 2
0
        public async Task <IActionResult> SetGlobals([FromBody] SyncData syncData)
        {
            try
            {
                await _db.CropTypes.AddOrUpdateRange(syncData.CropTypes, (a, b) => a.Name == b.Name);

                await _db.Placements.AddOrUpdateRange(syncData.Placements, (a, b) => a.Id == b.Id);

                await _db.Parameters.AddOrUpdateRange(syncData.Parameters, (a, b) => a.Id == b.Id);

                await _db.Subsystems.AddOrUpdateRange(syncData.SubSystems, (a, b) => a.Id == b.Id);

                await _db.SensorTypes.AddOrUpdateRange(syncData.SensorTypes, (a, b) => a.Id == b.Id);
            }
            catch (Exception e)
            {
                _logger.LogError(LogIds.EditGlobalData, e, "Failed to SetGlobals.");
                return(BadRequest("Data invalid or corrupt."));
            }
            return(new OkResult());
        }