public IActionResult EnvironmentRecords() { Random random = new Random(); List <EnvironmentRecord> entities = new List <EnvironmentRecord>(); for (int i = 1; i < 1000; i++) { var record = new EnvironmentRecord(); var rLatitudeD = random.NextDouble(); var rLongitudeD = random.NextDouble(); record.Longitude = 69 + rLongitudeD; record.Latitude = 41 + rLatitudeD; record.Quality = random.Next(0, 300); record.Temperature = random.Next(-20, 50); record.NoiseLevel = random.Next(0, 100); record.Humidity = random.Next(0, 50); record.Pressure = random.Next(0, 50); record.CreatedDate = DateTime.Now; record = _environmentRecordEntityService.Create(record); entities.Add(record); } _environmentRecordEntityService.Save(); var models = _mapper.Map <IEnumerable <EnvironmentRecord>, IEnumerable <EnvironmentRecordViewModel> >(entities); return(Ok(models)); }
public IActionResult Post([FromBody] EnvironmentRecordPostModel model) { if (model.Keyword != _configuration["Settings:Keyword"]) { return(BadRequest("Wrong keyword")); } try { var entity = _mapper.Map <EnvironmentRecord>(model); #region Temporary code Random random = new Random(); var rLatitudeD = random.NextDouble(); var rLongitudeD = random.NextDouble(); entity.Longitude = 69 + rLongitudeD; entity.Latitude = 41 + rLatitudeD; #endregion entity.CreatedDate = DateTime.Now; entity = _entityService.Create(entity, false); _entityService.Save(); var result = _mapper.Map <EnvironmentRecord, EnvironmentRecordViewModel>(entity); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }