// GET: Sensors/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } SensorEditViewModel sensor = await _context.Sensors.Select(m => new SensorEditViewModel { SensorId = m.SensorId, Name = m.Name, Metadata = m.Metadata, DataTypeId = m.DataType.DataTypeId, DatatypeScheme = m.DataType.Schema, CommunicationProtocolId = m.CommunicationProtocolId, IpAddress = m.IpAddress, Port = m.Port }).FirstOrDefaultAsync(m => m.SensorId == id).ConfigureAwait(true); if (sensor == null) { return(NotFound()); } ViewData["CommunicationProtocolId"] = new SelectList(_context.CommunicationProtocols, "CommunicationProtocolId", "ProtocolName", sensor.CommunicationProtocolId); return(View(sensor)); }
public async Task <IActionResult> Edit(SensorEditViewModel model) { try { var sensor = await _userSensorService.FindAsync(model.Id); if (sensor == null) { throw new ApplicationException($"Unable to find sensor with ID '{model.Id}'."); } if (sensor.Longitude != model.Longitude || sensor.Latitude != model.Latitude) { await _userSensorService.ChangeCoordinatesAsync(model.Id, model.Longitude, model.Latitude); } if (sensor.UserMinValue != model.MinValue || sensor.UserMaxValue != model.MaxValue) { await _userSensorService.ChangeMinMaxAsync(model.Id, model.MinValue, model.MaxValue); } if (sensor.IsPublic != model.IsPublic) { await _userSensorService.ChangeIsPublicAsync(model.Id, model.IsPublic); } if (sensor.IsRequiredNotification != model.IsRequiredNotification) { await _userSensorService.ChangeIsRequiredNotificationAsync(model.Id, model.IsRequiredNotification); } if (sensor.Name != model.Name) { await _userSensorService.ChangeNameAsync(model.Id, model.Name); } if (sensor.Description != model.Description) { await _userSensorService.ChangeDescriptionAsync(model.Id, model.Description); } return(RedirectToAction(nameof(Index))); } catch { return(View("PageNotFound")); } }
public async Task <IActionResult> Edit(int id) { try { var sensor = await _userSensorService.FindAsync(id); var sensorType = _sensorService.Find(sensor.SensorId); if (sensor == null) { throw new ApplicationException($"Unable to find sensor with ID '{id}'."); } var sensorValidation = new SensorValidation(sensorType); var model = new SensorEditViewModel(sensor, sensorValidation); return(PartialView(model)); } catch { return(View("PageNotFound")); } }