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)); } }
// GET: SensorType/Edit/5 public async Task <ActionResult> Edit(int id) { var sensorTypeDto = await _sensorTypeManager.GetSensorTypeByIdAsync(id); if (sensorTypeDto != null) { EditSensorTypeViewModel sensorTypeViewModel = _mapper.Map <SensorTypeDto, EditSensorTypeViewModel>(sensorTypeDto); return(ViewComponent("SensorTypeEdit", sensorTypeViewModel)); } return(ViewComponent("SensorTypeEdit", null)); }