Beispiel #1
0
        public async Task <IActionResult> Putiot_calendarday(long id, iot_calendarday iot_calendarday)
        {
            if (id != iot_calendarday.id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!iot_calendardayExists(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());
        }
Beispiel #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));
        }
Beispiel #3
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));
        }
Beispiel #4
0
        public async Task <ActionResult <iot_calendarday> > Getiot_calendarday_getorcreatebydate(String pDate)
        {
            var iot_calendarday = await _context.iot_calendarday
                                  .Where(e => e.date == pDate)
                                  .FirstOrDefaultAsync();

            if (iot_calendarday == null)
            {
                var new_calendarday = new iot_calendarday {
                    date = pDate
                };
                return(await Postiot_calendarday(new_calendarday));
            }
            else
            {
                return(Ok(iot_calendarday));
            }
        }