Ejemplo n.º 1
0
        public static TempReading CreateTempReading(int ID)
        {
            TempReading tempReading = new TempReading();

            tempReading.id = ID;
            return(tempReading);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostTemperature(TempDto tempReadingDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var tempReading = new TempReading
            {
                Temp     = tempReadingDto.Temperature,
                Humidity = tempReadingDto.Humidity,
                Time     = Convert.ToDateTime(tempReadingDto.Timestamp)
            };

            using var dbContext = _db.CreateDbContext();

            dbContext.Temps.Add(tempReading);

            if (tempReading.Temp < LOWTEMP)
            {
                _ = _wp.SendNotificationToAll($"Low temp: {tempReading.Temp}");
            }

            try
            {
                return(Ok(await dbContext.SaveChangesAsync()));
            }
            catch (DbUpdateException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  new { message = "Error while creating new temperature reading." }));
            }
        }
Ejemplo n.º 3
0
        // POST: /TempReadings
        public async Task <IHttpActionResult> Post(TempReading tempReading)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TempReadings.Add(tempReading);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TempReadingExists(tempReading.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created(tempReading));
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Post([FromBody] TempReading ourReading)
        {
            // here is where we insert it into the database
            ReadingDataMapper ourMapper = new ReadingDataMapper();

            ourMapper.ReadingInsert(ourReading.Temp);

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Ejemplo n.º 5
0
        // DELETE: /TempReadings(5)
        public async Task <IHttpActionResult> Delete([FromODataUri] double key)
        {
            TempReading tempReading = await db.TempReadings.FindAsync(key);

            if (tempReading == null)
            {
                return(NotFound());
            }

            db.TempReadings.Remove(tempReading);
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 6
0
        // PUT: /TempReadings(5)
        public async Task <IHttpActionResult> Put([FromODataUri] double key, Delta <TempReading> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TempReading tempReading = await db.TempReadings.FindAsync(key);

            if (tempReading == null)
            {
                return(NotFound());
            }

            patch.Put(tempReading);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TempReadingExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(tempReading));
        }
Ejemplo n.º 7
0
 public void AddToTempReadings(TempReading tempReading)
 {
     base.AddObject("TempReadings", tempReading);
 }