Esempio n. 1
0
        public async Task <IActionResult> PutLogs([FromRoute] int id, [FromBody] Logs logs)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutSensorDatas([FromRoute] Guid id, [FromBody] RecordForUpdateDto record)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dataFromAzure = await _context.SensorDatas.SingleOrDefaultAsync(m => m.Id == id);

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

            var dataForAzure = Mapper.Map <SensorDatas>(record);

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SensorDatasExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    // For the logger file
                    throw new Exception("Updating a record failed on save.");
                }
            }

            _logger.LogInformation(100, $"Data with {id} ID has been updated at UTC time {DateTime.UtcNow}");
            return(NoContent());
        }