// POST api/values public string Post([FromBody] Switches switches) { List <string> rets = new List <string>(); // store return values for switchig if (isValid(switches.S1)) { rets.Add(LabService.TurnSwitch(0, GetState(switches.S1), Device)); } if (isValid(switches.S2)) { rets.Add(LabService.TurnSwitch(1, GetState(switches.S2), Device)); } if (isValid(switches.S3)) { rets.Add(LabService.TurnSwitch(2, GetState(switches.S3), Device)); } if (isValid(switches.S4)) { rets.Add(LabService.TurnSwitch(3, GetState(switches.S4), Device)); } if (rets.Contains("Fail")) { return("Fail"); } return("OK"); }
public string Get(string s1, string s2) { int s1State = GetState(s1); int s2State = GetState(s2); LabService.TurnSwitch(0, s1State); LabService.TurnSwitch(1, s2State); return("OK"); }
// POST api/switch public string Post([FromBody] Switches switches) { try { if ((switches.Device == null)) { return("Fail, No device specified"); } Device = switches.Device; if (switches.ApiKey == null || !switches.ApiKey.Equals(apiKey)) { return("Invalid ApiKey"); } List <string> rets = new List <string>(); // store return values for switchig if (isValid(switches.S1)) { rets.Add(LabService.TurnSwitch(0, GetState(switches.S1), Device)); } if (isValid(switches.S2)) { rets.Add(LabService.TurnSwitch(1, GetState(switches.S2), Device)); } if (isValid(switches.S3)) { rets.Add(LabService.TurnSwitch(2, GetState(switches.S3), Device)); } if (isValid(switches.S4)) { rets.Add(LabService.TurnSwitch(3, GetState(switches.S4), Device)); } if (rets.Contains("Fail")) { return("Fail"); } } catch (Exception) { return("Fail"); } return("OK"); }