Exemplo n.º 1
0
 public IActionResult Register(string userId)
 {
     try
     {
         var sensors     = this._sensorService.GetAll().ToList();
         var sensorTypes = this._sensorService.GetAllTypes().ToList();
         var model       = new RegisterSensorViewModel(sensors, sensorTypes, sensors);
         ViewBag.userId = userId;
         return(View(model));
     }
     catch
     {
         return(View("PageNotFound"));
     }
 }
Exemplo n.º 2
0
        public IActionResult Register(RegisterSensorViewModel model)
        {
            var adminRegistration = true;

            if (model.UserID == null)
            {
                model.UserID      = this._userManager.GetUserId(User);
                adminRegistration = false;
            }
            try
            {
                this._userSensorService.RegisterSensor(model.Longitude, model.Latitude, model.MinValue, model.MaxValue, model.UpdateInterval, model.Name, model.Description, model.IsPublic, model.IsRequiredNotification, model.Default, model.UserID, model.SensorId);
            }
            catch
            {
                TempData["InvalidModel"] = "Minimum value cannot be bigger than maximum value, please try again!";
                if (adminRegistration)
                {
                    return(RedirectToRoute(new
                    {
                        controller = "Sensor",
                        action = "Register",
                        userId = model.UserID,
                    }));
                }

                return(RedirectToRoute(new
                {
                    controller = "Sensor",
                    action = "Register"
                }));
            }

            if (model.UserID != this._userManager.GetUserId(User))
            {
                return(RedirectToAction("Index", "Sensor", new { area = "Administration" }));
            }

            return(RedirectToAction("Index", "Sensor"));
        }