/// <summary> /// Adds or changes a ContainerLevel object which consists of an ID and a fill level /// </summary> /// <param name="cl">ContainerLevel to update, consisting of an ID(int) and FillLevel(int)</param> public IHttpActionResult Post([FromBody] ContainerLevel cl) { Console.WriteLine("IN POST"); if (cl != null) { Console.WriteLine("CL NOT NULL"); if (ModelState.IsValid) { Console.WriteLine("Post made: " + cl.ID.ToString() + " level: " + cl.FillLevel.ToString()); Service.GetInstance().SetFillLevel(cl); return(Ok()); } } return(BadRequest(ModelState)); }
public ContainerLevel collectData() { if (_counter == 2) { _counter = 0; _fillLevel += 5; } if (_fillLevel > 99) { ContainerLevel temp = new ContainerLevel(_container, _fillLevel); _fillLevel = 0; return(temp); } _counter++; return(new ContainerLevel(_container, _fillLevel)); }
/// <summary> /// Adds or changes a ContainerLevel object which consists of an ID and a fill level which can be retrieved from the json found as a parameter /// </summary> /// <param name="jsonBody">body containing json, retrieved from a incomming post request.</param> public IHttpActionResult Post([FromBody] JSONBody jsonBody) { try { if (jsonBody != null) { if (ModelState.IsValid) { ContainerLevel cl = new ContainerLevel(jsonBody.dev_id, jsonBody.payload_fields.fill_level); service.SetFillLevel(cl); return(Ok()); } else { return(BadRequest(ModelState)); } } return(BadRequest(ModelState)); } catch (ArgumentException e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unfortunate son..."))); } }