public ActionResult Create(CompostData data) { if (data.Created == null) { data.Created = DateTime.UtcNow; } var previous = _context.CompostData.AsQueryable().Where(x => x.DeviceId == data.DeviceId && x.Created == data.Created).FirstOrDefault(); if (previous != null) { return(Conflict()); } var device = _context.Devices.Where(x => x.Id == data.DeviceId).FirstOrDefault(); if (device == null) { device = new Device() { Id = data.DeviceId }; _context.Devices.Add(device); _context.SaveChanges(); } data.Id = new Guid(); _context.CompostData.Add(data); _context.SaveChanges(); return(Ok()); }
private List <CompostData> GenerateMockCompostData() { List <CompostData> compostDataList = new List <CompostData>(); DateTime now = DateTime.UtcNow; CompostData data1 = new CompostData(Guid.NewGuid(), now.AddMinutes(-1).ToString(), 60.0f, 55f, 40f); CompostData data2 = new CompostData(Guid.NewGuid(), now.AddMinutes(-2).ToString(), 59.9f, 54f, 41f); CompostData data3 = new CompostData(Guid.NewGuid(), now.AddMinutes(-3).ToString(), 59.8f, 54f, 41f); CompostData data4 = new CompostData(Guid.NewGuid(), now.AddMinutes(-4).ToString(), 59.7f, 53f, 42f); CompostData data5 = new CompostData(Guid.NewGuid(), now.AddMinutes(-5).ToString(), 59.8f, 54f, 41f); compostDataList.Add(data1); compostDataList.Add(data2); compostDataList.Add(data3); compostDataList.Add(data4); compostDataList.Add(data5); return(compostDataList); }