コード例 #1
0
        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"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Edit(SensorDetailsViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                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 (model.Default == null)
                {
                    if (sensor.UserMinValue != model.MinValue || sensor.UserMaxValue != model.MaxValue)
                    {
                        await _userSensorService.ChangeMinMaxAsync(model.Id, model.MinValue, model.MaxValue);
                    }
                }
                else
                {
                    if (sensor.UserMinValue != int.Parse(model.Default))
                    {
                        await _userSensorService.ChangeMinMaxAsync(model.Id, int.Parse(model.Default), int.Parse(model.Default));
                    }
                }

                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.UpdateInterval != model.UpdateInterval)
                {
                    await _userSensorService.ChangeUpdatenIntervalAsync(model.Id, model.UpdateInterval);
                }

                if (sensor.Description != model.Description)
                {
                    await _userSensorService.ChangeDescriptionAsync(model.Id, model.Description);
                }

                var usersensors = await _userSensorService.FilterAllSensorsAsync();

                var newModel = new SensorIndexViewModel(usersensors);

                return(View("Index", newModel));
            }
            catch
            {
                return(View("PageNotFound"));
            }
        }