コード例 #1
0
        public async Task <IActionResult> PutLeitura([FromRoute] int id, [FromBody] Leitura leitura)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != leitura.IdLeitura)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
ファイル: LeituraC.cs プロジェクト: Jaderhe/estacao
        public async Task <IActionResult> GetLeitura([FromQuery] String hash, [FromQuery] int veloc, [FromQuery] int umid, [FromQuery] int temp)
        {
            if ((string.Compare("6e1bbb5671b2dd6de8292c8374a1c01a", hash, false) != 0))
            {
                return(BadRequest(ModelState));
            }

            decimal umidade, temperatura, rpm, velocidade = 0;
            decimal pi = (decimal)3.14159265;

            umidade     = umid / 10;
            temperatura = temp / 10;
            rpm         = (veloc * 60) / 10;
            velocidade  = (((4 * pi * 147 * rpm) / 60) / 1000) * (decimal)3.6;
            velocidade  = Decimal.Round(velocidade, 2);


            Leitura leitura = new Leitura();

            leitura.Data  = System.DateTime.Now;
            leitura.Hash  = hash;
            leitura.Temp  = temperatura;
            leitura.Umid  = umidade;
            leitura.Veloc = velocidade;


            _context.Leitura.Add(leitura);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLeitura", new { id = leitura.IdLeitura }, leitura));
        }