public HttpResponseMessage Post(Device device) { this.deviceRepository.SaveDevice(device); var response = Request.CreateResponse<Device>(HttpStatusCode.Created, device); return response; }
/// <summary> /// Retrieves the Rachio Device Data /// </summary> /// <returns>The deserialized Device data or empty if it fails CheckStatus</returns> public static Device GetDevice(string id) { Device device = new Device(); device = (Device)RestSharpExtensions.ExecuteAPICall<Device>(device, String.Format("public/device", id), Method.GET); return device; }
public DeviceRepository() { var ctx = HttpContext.Current; if (ctx != null) { if (ctx.Cache[CacheKey] == null) { var devices = new Device[] { new Device { Id = "2a5e7d3c-c140-4e2e-91a1-a212a518adc5", Status = "ONLINE" } }; ctx.Cache[CacheKey] = devices; } } }
public bool SaveDevice(Device device) { var ctx = HttpContext.Current; if (ctx != null) { try { var currentData = ((Device[])ctx.Cache[CacheKey]).ToList(); currentData.Add(device); ctx.Cache[CacheKey] = currentData.ToArray(); return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } } return false; }