public SensorGroupViewModel(SensorGroup sensorGroup) { this.Id = sensorGroup.Id; this.Name = sensorGroup.Name; if (!String.IsNullOrEmpty(sensorGroup.TimeStamp)) { if (!String.IsNullOrEmpty(sensorGroup.Name)) { this.Name += " " + DateTimeUtil.HowLongAgo(sensorGroup.TimeStamp); } } List <SensorViewModel> sensors = new List <SensorViewModel>(); List <SensorValueViewModel> values = new List <SensorValueViewModel>(); if (sensorGroup.Items != null) { foreach (var sensor in sensorGroup.Items) { if (sensor.Value?.Values != null) { var sensorViewModel = new SensorViewModel(sensor.Value); if (sensorViewModel.Values != null && sensorViewModel.Values.Any()) { values.AddRange(sensorViewModel.Values); } } } } this.Sensors = sensors; this.SensorValues = values; }
public async Task <IActionResult> Update([FromRoute] int sensorId, [FromBody] SensorViewModel sensor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dbSensor = new Sensor() { Id = sensorId, DeviceId = sensor.DeviceId, Name = sensor.Name }; _context.Sensors.Update(dbSensor); var sensorProperties = sensor.Properties.Select(sp => new SensorProperty() { SensorId = dbSensor.Id, Name = sp.Name, Value = sp.Value }); _context.SensorProperties.RemoveRange(_context.SensorProperties.Where(sp => sp.SensorId.Equals(sensorId))); _context.SensorProperties.AddRange(sensorProperties); await _context.SaveChangesAsync(); var sensorModel = dbSensor.ToViewModel(); sensorModel.Properties = sensorProperties.Select(sp => sp.ToViewModel()); return(Ok(sensorModel)); }
public async Task <IActionResult> Edit(int id, [Bind("SensorId,Identificator,Units,Name,Description,Groups")] SensorViewModel sensor) { var sensorData = await _context.Sensors.Include(x => x.Groups).FirstAsync(x => x.SensorId == id); if (sensorData == null) { return(NotFound()); } if (ModelState.IsValid) { try { _mapper.Map(sensor, sensorData); _context.Update(sensorData); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SensorExists(sensor.SensorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(sensor)); }
public ActionResult ShowDetails(int id) { var sensor = this.sensorService.GetUserSensorById(id); if (sensor == null) { return(this.View("NotAuthenticated")); } var sensorViewModel = new SensorViewModel() { Id = sensor.Id, CurrentValue = sensor.CurrentValue, Name = sensor.Name, Description = sensor.Description, Url = sensor.URL, IsValueType = !sensor.IsBoolType, PollingInterval = sensor.PollingInterval, MeasurementType = sensor.MeasurementType, IsPublic = sensor.IsPublic, IsShared = sensor.IsShared, IsReadOnly = true }; return(this.View("ShowDetails", sensorViewModel)); }
public SensorController(IHttpContextAccessor httpContextAccessor, IMemoryCache memoryCache) { _httpContextAccessor = httpContextAccessor; _cache = memoryCache; SensorViewModel model = new SensorViewModel(_cache); }
public SensorViewModel Get(int sensorId) { SensorViewModel sensor = null; var now = DateTime.Now; using (var dbContext = new Entities()) { var dbSensor = dbContext.Sensors.FirstOrDefault(s => s.Id == sensorId); var sensorMeasurements = dbSensor.SensorMeasurements.Where(sm => sm.MeasureDate > now.AddDays(-5)); if (dbSensor != null) { sensor = new SensorViewModel() { Id = dbSensor.Id, SensorName = dbSensor.SensorName, Description = dbSensor.Description, MinValue = sensorMeasurements.Any() ? dbSensor.SensorMeasurements.Min(sm => sm.Value) : 0, MaxValue = sensorMeasurements.Any() ? dbSensor.SensorMeasurements.Max(sm => sm.Value) : 0, Measurements = sensorMeasurements.Select(sm => new SensorMeasurementsViewModel() { DeviceId = sm.DeviceId, Id = sm.Id, Lat = sm.Lat, Long = sm.Long, MeasureDate = sm.MeasureDate, SensorId = sm.SensorId, Value = sm.Value }) }; } } return(sensor); }
public IActionResult Modify(SensorViewModel sensorViewModel) { if (!ModelState.IsValid) { return(this.View()); } var sensor = sensorService.GetSensorById(sensorViewModel.ID); sensor.Name = sensorViewModel.Name; sensor.Description = sensorViewModel.Description; sensor.PoolInterval = sensorViewModel.PollingIntervalInSeconds; sensor.Latitude = sensorViewModel.Latitude; sensor.Longitude = sensorViewModel.Longitude; sensor.ValueRangeMin = sensorViewModel.ValueRangeMin; sensor.ValueRangeMax = sensorViewModel.ValueRangeMax; sensor.IsPublic = sensorViewModel.IsPublic; sensorService.UpdateSensor(editedSensor: sensor); //string actionName = nameof(this.Details); //string controllerName = nameof(SensorController).Replace("Controller", ""); //int routeValue = sensor.ID; //return RedirectToAction(actionName, controllerName, routeValue); return(RedirectToAction("Index", "Home")); }
public async Task Create_WithValidSensor_ReturnsCreatedSensor() { // Arrange var testSensor = new SensorViewModel() { DeviceId = 1, Name = "TestSensor", Properties = new List <SensorPropertyViewModel>() { new SensorPropertyViewModel() { Name = "Property", Value = "JSDH6H" } } }; var dbContext = Setup.GetDbContext(); var controller = new SensorController(dbContext); // Act var result = await controller.Create(testSensor); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); var sensor = Assert.IsAssignableFrom <SensorViewModel>(okObjectResult.Value); Assert.Equal(1, sensor.Id); Assert.Equal(testSensor.Name, sensor.Name); Assert.All(testSensor.Properties, testSensorProperty => { var sensorProperty = sensor.Properties.SingleOrDefault(sp => sp.Name.Equals(testSensorProperty.Name)); Assert.NotNull(sensorProperty); Assert.Equal(testSensorProperty.Value, sensorProperty.Value); }); }
public ActionResult Edit(Guid id) { CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString()); SensorViewModel model = new SensorViewModel(_cache, id); return(View(model)); }
public ActionResult ShareSensor(int id) { var sensor = this.sensorService.GetUserSensorById(id); if (this.User.Identity.GetUserId() != sensor.OwnerId) { return(View("NotAuthenticated")); } var sensorViewModel = new SensorViewModel() { Id = sensor.Id, CurrentValue = sensor.CurrentValue, Name = sensor.Name, Description = sensor.Description, Url = sensor.URL, PollingInterval = sensor.PollingInterval, IsValueType = !sensor.IsBoolType, MeasurementType = sensor.MeasurementType, IsPublic = sensor.IsPublic, IsShared = sensor.IsShared }; return(View("ShareSensor", sensorViewModel)); }
private async void SensorConfigMenu_Delete_ClickAsync(object sender, RoutedEventArgs e) { MenuFlyoutItem configMenuItem = (MenuFlyoutItem)sender; Tuple <SensorViewModel, Rectangle, Viewbox, CompositeTransform> sensorTuple = (Tuple <SensorViewModel, Rectangle, Viewbox, CompositeTransform>)configMenuItem.Tag; SensorViewModel sensorViewModel = sensorTuple.Item1; string message = "Are you sure that you want to perminantly remove sensor " + sensorViewModel.Name + "?"; var dialog = new Windows.UI.Popups.MessageDialog(message, "Remove Sensor"); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Yes") { Id = 0 }); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Cancel") { Id = 1 }); var result = await dialog.ShowAsync(); if (result.Label == "Yes") { // Remove Sensor sensorCanvas.Children.Remove(sensorTuple.Item2); sensorCanvas.Children.Remove(sensorTuple.Item3); _viewModel.RemoveSensor(sensorViewModel); canvasSensorList.Remove(sensorTuple); sensorCanvas.InvalidateArrange(); sensorCanvas.UpdateLayout(); } }
private void Sensor_RightTapped(object sender, RightTappedRoutedEventArgs e) { Rectangle sensorRect = null; SensorViewModel sensorViewModel = null; Tuple <SensorViewModel, Rectangle, Viewbox, CompositeTransform> tuple = FindSensorIndexInTupleList(sender); if (tuple == null) { return; } sensorViewModel = tuple.Item1; sensorRect = tuple.Item2; _viewModel.SensorCategorySelected = SensorType.GetSensorCategory(sensorViewModel.SensorTypes[0].Category); _viewModel.SensorSelected = sensorViewModel; MenuFlyout sensorConfigMenu = new MenuFlyout(); MenuFlyoutItem sensorConfigMenu_Config = new MenuFlyoutItem { Text = "Edit", Tag = tuple }; sensorConfigMenu_Config.Click += BtnEditSensor_ClickAsync; MenuFlyoutItem sensorConfigMenu_Delete = new MenuFlyoutItem { Text = "Delete", Tag = tuple }; sensorConfigMenu_Delete.Click += SensorConfigMenu_Delete_ClickAsync; sensorConfigMenu.Items.Add(sensorConfigMenu_Config); sensorConfigMenu.Items.Add(sensorConfigMenu_Delete); sensorConfigMenu.ShowAt(sensorRect, new Point(sensorRect.ActualWidth, sensorRect.ActualHeight)); }
public SensorViewModel GetSensorViewModel() { var sensorViewModel = new SensorViewModel(); var departements = departementRepository.GetAllDepartments(); sensorViewModel.Departements = departements; return(sensorViewModel); }
public async Task Update_WithValidSensor_ReturnsUpdatedSensor() { // Arrange var testSensor = new SensorViewModel() { DeviceId = 1, Name = "TestSensor", Properties = new List <SensorPropertyViewModel>() { new SensorPropertyViewModel() { Name = "Property", Value = "JSDH6H" } } }; var dbContext = Setup.GetDbContext(); var sensorEntry = dbContext.Sensors.Add(new Sensor() { Id = 10, DeviceId = 1, Name = "SensorName" }); var sensorProperty1 = dbContext.SensorProperties.Add(new SensorProperty() { SensorId = 10, Name = "Property", Value = "KDU8J" }); var sensorProperty2 = dbContext.SensorProperties.Add(new SensorProperty() { SensorId = 10, Name = "Key", Value = "12DE83" }); await dbContext.SaveChangesAsync(); sensorEntry.State = EntityState.Detached; sensorProperty1.State = EntityState.Detached; sensorProperty2.State = EntityState.Detached; var controller = new SensorController(dbContext); // Act var result = await controller.Update(10, testSensor); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); var sensor = Assert.IsAssignableFrom <SensorViewModel>(okObjectResult.Value); Assert.Equal(10, sensor.Id); Assert.Equal(testSensor.Name, sensor.Name); Assert.All(testSensor.Properties, testSensorProperty => { var sensorProperty = sensor.Properties.SingleOrDefault(sp => sp.Name.Equals(testSensorProperty.Name)); Assert.NotNull(sensorProperty); Assert.Equal(testSensorProperty.Value, sensorProperty.Value); }); }
public UserSensorWithData(SensorViewModel viewModel) { this.DeviceId = viewModel.DeviceId; this.Id = viewModel.Id; this.Location = viewModel.Location; this.Name = viewModel.Name; this.SensorType = viewModel.SensorType; SensorTypeId = viewModel.SensorTypeId; }
// GET: /<controller>/ public IActionResult Index() { var viewmodel = new SensorViewModel() { Sensors = _sensorRepository.GetAllSensors().ToList() }; return(View(viewmodel)); }
public async Task <IActionResult> Put(SensorViewModel sensorModel) { var sensor = _mapper.Map <SensorViewModel, Sensor>(sensorModel); _context.Entry(sensor).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> Post(SensorViewModel sensorModel) { var sensor = _mapper.Map <SensorViewModel, Sensor>(sensorModel); _context.Add(sensor); await _context.SaveChangesAsync(); return(Ok(sensor.ID)); }
public ActionResult AddSensor() { var userId = GetUserId(); var model = new SensorViewModel { AveableDevices = deviceManager.GetDevices(userId) }; return(View(model)); }
public async Task <IActionResult> EditSensor(SensorViewModel viewModel) { var sensorMinMaxValuesList = new List <double>(await this.userSensorService.GetSensorsTypeMinMaxValues(viewModel.Tag)); viewModel.SensorTypeMinVal = sensorMinMaxValuesList[0]; viewModel.SensorTypeMaxVal = sensorMinMaxValuesList[1]; return(View(viewModel)); }
public ActionResult CreateSensor(SensorViewModel model) { if (ModelState.IsValid) { var sensor = new DataflowICB.Database.Models.Sensor() { OwnerId = this.User.Identity.GetUserId(), Description = model.Description, IsPublic = model.IsPublic, Name = model.Name, URL = model.Url, PollingInterval = model.PollingInterval, LastUpdate = DateTime.Now }; if (model.IsValueType) { var valueType = new ValueTypeSensor() { MeasurementType = model.MeasurementType, //IsInAcceptableRange = model.ValueTypeSensor.IsInAcceptableRange, Maxvalue = model.MaxValue, MinValue = model.MinValue }; sensor.IsBoolType = false; sensor.ValueTypeSensor = valueType; } else { var boolType = new BoolTypeSensor() { MeasurementType = model.MeasurementType }; sensor.IsBoolType = true; sensor.BoolTypeSensor = boolType; } this.sensorService.AddSensor(sensor); return(this.Json("Successfully Registered !")); } else { if (model.IsValueType) { return(this.View("RegisterValueSensor", model)); } else { return(this.View("RegisterBoolSensor", model)); } } }
public void Put(int id, [FromBody] SensorViewModel model) { var sensor = this._db.sensores.Single(s => s.Id == id); sensor.acao = model.acao; sensor.tipo = model.tipo; sensor.valor = model.valor; this._db.sensores.Update(sensor); this._db.SaveChanges(); }
public ActionResult CreateSensor(SensorViewModel model) { if (this.ModelState.IsValid) { model.OwnerId = this.userManager.FindByNameAsync(this.User.Identity.Name).Result.Id; this.service.CreateSensor(model); return(this.RedirectToAction("MySensors")); } ; return(this.View()); }
public async Task <IActionResult> RegisterSensor(SensorViewModel model) { if (!this.ModelState.IsValid) { return(View(model)); } await this.userSensorService.AddSensorAsync(model.UserId, model.Id, model.Name, model.Description, model.MinValue, model.MaxValue, model.PollingInterval, model.Latitude, model.Longtitude, model.IsPublic, model.Alarm, model.ImageURL); return(RedirectToAction("Index", "Home", new { area = "" })); }
public IActionResult Post([FromBody] SensorViewModel model) { if (model == null) { return(StatusCode(500, new InternalServerError())); } if (!ModelState.IsValid) { return(StatusCode(500, new InternalServerError("Incorrect data!"))); } var sensor = _context.Sensors .Include(p => p.SensorType) .Where(p => p.Id == model.Id) .FirstOrDefault(); if (sensor == null) { return(NotFound(new NotFoundError())); } var user = User.GetUser(_context); var userHasController = _context.UserHasControllers .Where(p => p.ControllerId == sensor.ControllerId) .Where(p => p.UserId == user.Id) .Where(p => p.IsAdmin); if (userHasController == null) { return(Unauthorized(new UnauthorizedError())); } var sensors = _context.Sensors .Where(p => p.ControllerId == sensor.ControllerId) .Where(p => p.Pin == sensor.Pin) .Where(p => p.Id != sensor.Id); //Перевіряємо чи до цього піну підключені інші сенсори if (sensors.Any()) { return(StatusCode(500, new InternalServerError("Pin is already taken!"))); } //змінюємо модель sensor.Name = model.Name; sensor.Pin = model.Pin; sensor.Status = model.Status; sensor.SensorTypeId = model.SensorTypeId; _context.SaveChanges(); return(Json(sensor.Adapt <SensorViewModel>())); }
public ActionResult EditSensor(SensorViewModel model) { if (this.ModelState.IsValid) { var userId = this.userManager.GetUserId(this.User); this.service.EditSensor(model, userId); return(this.RedirectToAction("EditSensors")); } ; return(this.View()); }
public void TestSensorViewModel() { var viewmodel = new SensorViewModel(sensorService); ObservableCollection <Sensor> expectedData = new ObservableCollection <Sensor>(sensorService.All()); var sensor = sensorService.Find(1); viewmodel.SelectedSensor = sensor; Assert.AreEqual(expectedData.Count, viewmodel.Sensors.Count); Assert.IsNotNull(viewmodel.SelectedSensor); Assert.AreEqual(1, viewmodel.SelectedSensor.Sensor_id); }
public SensorViewModel GetrealTimeSensorsData(int id) { SensorViewModel sensor = new SensorViewModel(); //Parent parent = Parents.Where(p => // p.Zone == zone // && p.parentNumber == parentNumber).First(); //for (int i = 0; i < 3; i++) //{ // sensor.Sensor[i] = parent.Sensor[i].GetLatestData(); //} return(sensor); }
public Sensor Post([FromBody] SensorViewModel model) { var sensor = new Sensor(); sensor.acao = model.acao; sensor.tipo = model.tipo; sensor.valor = model.valor; sensor.veiculo = this._db.veiculos.Single(s => s.Id == model.veiculoId); this._db.sensores.Add(sensor); this._db.SaveChanges(); return(sensor); }
public SensorDataPage(Device currentDevice) { logger.TAG = "SensorDataPage"; logger.LogInfo(String.Format("{0} - {1}", currentDevice.Name, currentDevice.Address)); sensorViewModel = new SensorViewModel(new DeviceViewModel(currentDevice.Name, currentDevice.Address)); nativeSensorData.Init(sensorViewModel, currentDevice); this.BindingContext = sensorViewModel; logger.TraceInformation("---- The ending of the problem place. -----"); logger.TraceInformation("--------------------------------------------"); InitializeComponent(); }
private void GetSensorsWithPrices() { var phenomenas = Enum.GetValues(typeof(SensingPhenomena)).Cast<SensingPhenomena>(); foreach (var phenomena in phenomenas) { var sensor = new SensorViewModel{Phenomena = phenomena}; sensor.Price = GetPhenomenaDefaultPrice(phenomena); Sensors.Add(sensor); } }