Beispiel #1
0
        public async Task <IActionResult> PutHost([FromRoute] string id, [FromBody] Host host)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != host.IpAddress)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
 public ActionResult Edit([Bind(Include = "TemperatureId,Time,Celcius,Location")] TemperatureModel temperatureModel)
 {
     if (ModelState.IsValid)
     {
         Temperature temperature = new Temperature()
         {
             TemperatureId = temperatureModel.TemperatureId, Celcius = temperatureModel.Celcius, Time = temperatureModel.Time, Location = temperatureModel.Location
         };
         db.Entry(temperature).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(temperatureModel));
 }
        public async Task <IHttpActionResult> PutTemperature(int id, TemperatureModel temperatureModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Temperature temperature = new Temperature()
            {
                TemperatureId = temperatureModel.TemperatureId, Celcius = temperatureModel.Celcius, Time = temperatureModel.Time, Location = temperatureModel.Location
            };

            if (id != temperature.TemperatureId)
            {
                return(BadRequest());
            }

            db.Entry(temperature).State = EntityState.Modified;

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

            return(Ok(temperatureModel));
        }