public async Task <IHttpActionResult> PutDetectPanic(long id, DetectPanic detectPanic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetDetectPanic(long id)
        {
            DetectPanic detectPanic = await db.DetectPanics.FindAsync(id);

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

            return(Ok(detectPanic));
        }
        public async Task <IHttpActionResult> GetLastDetection()
        {
            int last = await db.DetectPanics.CountAsync();

            DetectPanic detectPanic = await db.DetectPanics.FindAsync(last);

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

            return(Ok(detectPanic));
        }
        public async Task <IHttpActionResult> DeleteDetectPanic(long id)
        {
            DetectPanic detectPanic = await db.DetectPanics.FindAsync(id);

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

            db.DetectPanics.Remove(detectPanic);
            await db.SaveChangesAsync();

            return(Ok(detectPanic));
        }
        public async Task <IHttpActionResult> PostDetectPanic(DetectPanic detectPanic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var hub = GlobalHost.ConnectionManager.GetHubContext <MyHub>();

            hub.Clients.All.broadcastMessage("Panic", detectPanic.IsPistol, detectPanic.BoxesValue);

            db.DetectPanics.Add(detectPanic);
            await db.SaveChangesAsync();

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