public async Task <IActionResult> NotificationsDevice(string id, [FromQuery] string token) { try { using (DbWaterRecyclingContext db = new DbWaterRecyclingContext()) { var code = await db.Devices.Where(i => i.Code.Equals(id)).FirstOrDefaultAsync(); if (code == null) { return(BadRequest()); } code.DeviceToken = token; db.Update(code); await db.SaveChangesAsync(); Notifications.Notify notify = new Notifications.Notify(); notify.NotifyNewDevice(code); return(Ok(10)); } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }
public async Task <IActionResult> RemoveCode(string id) { try { using (DbWaterRecyclingContext db = new DbWaterRecyclingContext()) { var code = await db.Devices.Where(i => i.Code.Equals(id)).FirstOrDefaultAsync(); if (code == null) { return(BadRequest("Código Incorrecto")); } if (code.State) { code.State = false; db.Update(code); await db.SaveChangesAsync(); return(Ok("Dispositivo Desasociado correctamente")); } return(BadRequest("El código no está asociado a ningun dispositivo")); } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }
public async Task <IActionResult> ActivateCode(string id) { try { using (DbWaterRecyclingContext db = new DbWaterRecyclingContext()) { var code = await db.Devices.Where(i => i.Code.Equals(id)).FirstOrDefaultAsync(); if (code == null) { return(BadRequest()); } if (code.State) { return(Ok(99)); } code.State = true; db.Update(code); await db.SaveChangesAsync(); return(Ok(10)); } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }