Beispiel #1
0
        public IHttpActionResult PutIot(int id, Iot iot)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != iot.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IotExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> GetIot(int id)
        {
            Iot iot = await new IotService(_db).GetIotsAsync(id);

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

            return(Ok(iot));
        }
Beispiel #3
0
        public IHttpActionResult GetIot(int id)
        {
            Iot iot = db.Iots.Find(id);

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

            return(Ok(iot));
        }
Beispiel #4
0
        public IHttpActionResult DeleteIot(int id)
        {
            Iot iot = db.Iots.Find(id);

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

            db.Iots.Remove(iot);
            db.SaveChanges();

            return(Ok(iot));
        }
Beispiel #5
0
        public IHttpActionResult PostIot(Iot iot)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Iots.Add(iot);
            IEnumerable <Constituent> Constituents = iot.Constituents;

            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = iot.Id }, iot));
        }