Example #1
0
        public async Task <ActionResult <Measure> > PostSensor(Sensor sensor)
        {
            if (!this.HttpContext.Request.Host.Value.StartsWith("localhost"))
            {
                return(Unauthorized());
            }

            _context.Sensors.Add(sensor);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Example #2
0
        public async Task <ActionResult <Measure> > Post(/* [FromBody]*/ Measure measure)
        {
            if (!this.HttpContext.Request.Host.Value.StartsWith("localhost"))
            {
                return(Unauthorized());
            }

            if (_context.Measures.Any(x => x.SensorId == measure.SensorId && x.DateTime == measure.DateTime))
            {
                return(BadRequest());
            }

            _context.Measures.Add(measure);
            await _context.SaveChangesAsync();

            //return CreatedAtAction(nameof(measure), measure);
            return(StatusCode(201));
        }