コード例 #1
0
        public async Task<IHttpActionResult> PutTempReading(int id, TempReading tempReading)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != tempReading.ID)
            {
                return BadRequest();
            }

            db.Entry(tempReading).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public async Task<IHttpActionResult> PostTempReading(TempReading tempReading)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            return CreatedAtRoute("DefaultApi", new { id = tempReading.ID }, tempReading);
        }