Exemplo n.º 1
0
        public async Task <ActionResult> Create(CreateSensorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            SensorDto     sensorDto  = _mapper.Map <CreateSensorViewModel, SensorDto>(model);
            SensorTypeDto sensorType = await _sensorTypeManager.GetSensorTypeByIdAsync(sensorDto.SensorTypeId);

            if (model.IconFile != null)
            {
                sensorDto.IconId = await _iconManager.CreateAndGetIconId(model.IconFile);
            }
            else
            {
                sensorDto.IconId = sensorType.IconId;
            }

            var res = await _sensorManager.Create(sensorDto);

            if (res != null)
            {
                res.SensorTypeName = sensorType.Name;
                return(ViewComponent("SensorElement", _mapper.Map <SensorDto, SensorViewModel>(res)));
            }
            else
            {
                //ModelState.AddModelError(res.Property, res.Message);
                return(View(model));
            }
        }
 public IViewComponentResult Invoke(CreateSensorViewModel model) => View(model);