public async Task <IActionResult> Post([FromBody] Service data) { MonitorAPI.Data.Service Service = new Data.Service(); var service = new Service(); service.Link = data.Link; service.TimeStamp = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz"); if (Service.GetStatus(service.Link)) { service.Status = true; } else { service.Status = false; } using (var db = new MonitorContext()) { db.Services.Add(service); await db.SaveChangesAsync(); } return(CreatedAtAction("GetService", new { id = service.Id }, service)); }
public async Task <IActionResult> Put(int id, Service data) { using (var db = new MonitorContext()) { var service = db.Services.SingleOrDefault(s => s.Id == id); if (service == null) { return(NotFound()); } service.TimeStamp = DateTime.Now.ToString("dd-MM-yyyyTHH:mm:sszzz"); service.Link = data.Link; MonitorAPI.Data.Service tester = new Data.Service(); if (tester.GetStatus(service.Link)) { service.Status = true; } else { service.Status = false; } db.Services.Update(service); await db.SaveChangesAsync(); return(Ok(service)); } }