コード例 #1
0
        public async Task <IActionResult> Putker_reftab(long id, ker_reftab ker_reftab)
        {
            if (id != ker_reftab.id)
            {
                return(BadRequest());
            }

            _context.Entry(ker_reftab).State = EntityState.Modified;

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

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.UPDATE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <iot_sample> > Postiot_sample(iot_sample iot_sample)
        {
            // if timestamp is not provided, default it to Now
            if (iot_sample.timestamp == DateTime.MinValue)
            {
                iot_sample.timestamp = DateTime.Now;
            }

            // calculate or validate calendarday
            String lTimestampDay = iot_sample.timestamp.ToString("yyyy-MM-dd");

            // start of hack (as I am not able to call another controller
            //var iot_calendarday = await iot_calendardayController.Getiot_calendarday_getorcreatebydate(lTimestampDay);
            var iot_calendarday = await _context.iot_calendarday.Where(cd => cd.date == lTimestampDay).FirstOrDefaultAsync();

            if (iot_calendarday == null)
            {
                iot_calendarday = new iot_calendarday {
                    date = lTimestampDay
                };
                _context.iot_calendarday.Add(iot_calendarday);
                await _context.SaveChangesAsync();

                var lMsg2  = new ServerUpdateHubMsg("iot_calendarday", ServerUpdateHubMsg.TOperation.INSERT, iot_calendarday.id);
                var lJson2 = JsonConvert.SerializeObject(lMsg2);
                await _hubContext.Clients.All.SendAsync(lMsg2.entity, lJson2);
            }
            // end of the hack

            if (iot_calendarday == null)
            {
                return(NotFound());
            }
            if (iot_sample.calendardayid == null)
            {
                iot_sample.calendardayid = iot_calendarday.id;
            }
            else
            if (iot_sample.calendardayid != iot_calendarday.id)
            {
                return(BadRequest());
            }

            _context.iot_sample.Add(iot_sample);
            await _context.SaveChangesAsync();

            iot_sample.device      = null;
            iot_sample.calendarday = null;

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, iot_sample.id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(CreatedAtAction("Getiot_sample", new { id = iot_sample.id }, iot_sample));
        }
コード例 #3
0
        public async Task <ActionResult <ker_reftab> > Postker_reftab(ker_reftab ker_reftab)
        {
            _context.ker_reftab.Add(ker_reftab);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, ker_reftab.id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(CreatedAtAction("Getker_reftab", new { id = ker_reftab.id }, ker_reftab));
        }
コード例 #4
0
        public async Task <ActionResult <iot_calendarday> > Postiot_calendarday(iot_calendarday iot_calendarday)
        {
            _context.iot_calendarday.Add(iot_calendarday);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, iot_calendarday.id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(CreatedAtAction("Getiot_calendarday", new { id = iot_calendarday.id }, iot_calendarday));
        }
コード例 #5
0
        public async Task <ActionResult <pcm_calevent> > Postpcm_calevent(pcm_calevent pcm_calevent)
        {
            _context.pcm_calevent.Add(pcm_calevent);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, pcm_calevent.id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(CreatedAtAction("Getpcm_calevent", new { id = pcm_calevent.id }, pcm_calevent));
        }
コード例 #6
0
        public async Task <ActionResult <iot_device> > Postiot_device(iot_device iot_device)
        {
            _context.iot_device.Add(iot_device);
            await _context.SaveChangesAsync();

            //await _hubContext.Clients.All.SendAsync("broadcastMessage", "name", "message from controller");
            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, iot_device.id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(CreatedAtAction("Getiot_device", new { id = iot_device.id }, iot_device));
        }
コード例 #7
0
        public async Task <IActionResult> Putiot_task_failed(long id, iot_task iot_task)
        {
            if (id != iot_task.id)
            {
                return(BadRequest());
            }

            _context.Entry(iot_task).State = EntityState.Modified;

            try
            {
                if (iot_task.completed.HasValue)
                {
                    await _context.Database.ExecuteSqlRawAsync(
                        "UPDATE iot_task SET " +
                        "  completed={1}, " +
                        "  taskstatusnm='FAILED' " +
                        "  WHERE id={0}",
                        parameters : new[] { iot_task.id.ToString(), iot_task.completed.ToString() });
                }
                else
                {
                    await _context.Database.ExecuteSqlRawAsync(
                        "UPDATE iot_task SET " +
                        "  completed=null, " +
                        "  taskstatusnm='FAILED' " +
                        "  WHERE id={0}",
                        parameters : iot_task.id);
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!iot_taskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.UPDATE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(NoContent());
        }
コード例 #8
0
        public async Task <ActionResult <ker_reftab> > Deleteker_reftab(long id)
        {
            var ker_reftab = await _context.ker_reftab.FindAsync(id);

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

            _context.ker_reftab.Remove(ker_reftab);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.DELETE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(ker_reftab);
        }
コード例 #9
0
        public async Task <ActionResult <iot_calendarday> > Deleteiot_calendarday(long id)
        {
            var iot_calendarday = await _context.iot_calendarday.FindAsync(id);

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

            _context.iot_calendarday.Remove(iot_calendarday);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.DELETE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(iot_calendarday);
        }
コード例 #10
0
        public async Task <ActionResult <pcm_calevent> > Deletepcm_calevent(long id)
        {
            var pcm_calevent = await _context.pcm_calevent.FindAsync(id);

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

            _context.pcm_calevent.Remove(pcm_calevent);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.DELETE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(pcm_calevent);
        }
コード例 #11
0
        public async Task <ActionResult <iot_device> > Copyiot_device(long sourceid, long?masterdeviceid)
        {
            var sourcedevice = await _context.iot_device.FindAsync(sourceid);

            if (sourcedevice == null)
            {
                return(NotFound());
            }
            var subdevices = await _context.iot_device.Where(d => d.masterdeviceid == sourcedevice.id).ToListAsync();

            var newdevice = new iot_device();

            sourcedevice.CopyAllPropertiesTo(newdevice);

            newdevice.id             = 0;
            newdevice.code           = sourcedevice.code + "_(1)";
            newdevice.name           = sourcedevice.name + " (1)";
            newdevice.masterdevice   = null;
            newdevice.masterdeviceid = (masterdeviceid == 0)?null:masterdeviceid;
            newdevice.iot_sample     = null;
            newdevice.iot_subdevice  = null;
            newdevice.iot_task       = null;


            /*
             * var lResult=await Postiot_device(iot_device);
             * iot_device newdevice = (ObjectResult)lResult.Result;
             */

            _context.iot_device.Add(newdevice);
            await _context.SaveChangesAsync();

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, newdevice.id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            for (int i = 0; i < subdevices.Count; i++)
            {
                await Copyiot_device(subdevices[i].id, newdevice.id);
            }

            // return lResult;
            return(CreatedAtAction("Getiot_device", new { id = newdevice.id }, newdevice));
        }
コード例 #12
0
        public async Task <ActionResult <pcm_calevent> > Getpcm_calevent(long id)
        {
            var pcm_calevent = await _context.pcm_calevent.FindAsync(id);

//            var pcm_calevent = await _context.pcm_calevent
//                                                .Include(d => d.customer)
//                                                .SingleOrDefaultAsync(d => d.id == id);

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

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.UPDATE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(pcm_calevent);
        }
コード例 #13
0
        public async Task <IActionResult> Putiot_sample(long id, iot_sample iot_sample)
        {
            if (id != iot_sample.id)
            {
                return(BadRequest());
            }

            if (iot_sample.importance == null)
            {
                iot_sample.importance = 0;
            }

            _context.Entry(iot_sample).State = EntityState.Modified;

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

            var lMsg  = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.UPDATE, id);
            var lJson = JsonConvert.SerializeObject(lMsg);
            await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson);

            return(NoContent());
        }