public async Task <ActionResult> Edit(EditSensorViewModel model) { SensorDto sensorDto = _mapper.Map <EditSensorViewModel, SensorDto>(model); IconDto iconDto = null; if (model.IconFile != null) { sensorDto.IconId = _iconManager.CreateAndGetIconId(model.IconFile).Result; iconDto = await _iconManager.GetById(sensorDto.IconId.GetValueOrDefault()); sensorDto.IconPath = iconDto.Path; } var res = await _sensorManager.Update(sensorDto); if (res != null) { res = await _sensorManager.GetSensorByIdAsync(sensorDto.Id); iconDto = await _iconManager.GetById(sensorDto.IconId.GetValueOrDefault()); sensorDto.IconPath = iconDto.Path; sensorDto.SensorTypeName = res.SensorTypeName; return(ViewComponent("SensorElement", _mapper.Map <SensorDto, SensorViewModel>(sensorDto))); } else { //ModelState.AddModelError(res.Property, res.Message); return(View(model)); } }
public async Task <IActionResult> Edit(EditDashboardViewModel model) { if (!ModelState.IsValid) { return(View(model)); } DashboardDto dashboardDto = _mapper.Map <EditDashboardViewModel, DashboardDto>(model); IconDto iconDto = null; if (model.IconFile != null) { dashboardDto.IconId = await _iconManager.CreateAndGetIconId(model.IconFile); iconDto = await _iconManager.GetById(dashboardDto.IconId.GetValueOrDefault()); dashboardDto.IconPath = iconDto.Path; } dashboardDto.AppUserId = _userManager.GetUserId(User); var res = _dashboardManager.Update(dashboardDto).Result; if (res != null) { res = _dashboardManager.GetById(res.Id).Result; DashboardViewModel dashmodel = _mapper.Map <DashboardDto, DashboardViewModel>(res); if (model.IconFile == null) { iconDto = await _iconManager.GetById(dashboardDto.IconId.GetValueOrDefault()); dashboardDto.IconPath = iconDto.Path; } if (!dashmodel.IsPublic) { dashmodel.DashCreatorUserName = User.Claims.ElementAt(1).Value; } return(ViewComponent("DashboardElement", dashmodel)); } else { //ModelState.AddModelError(res.Property, res.Message); return(View(model)); } }
public async Task <IActionResult> Index() { var user = await _userManager.GetUserAsync(User); var image = await _iconManager.GetById(user.IconId.Value); var model = new ProfileViewModel { Id = user.Id, Email = user.Email, PhoneNumber = user.PhoneNumber, FirstName = user.FirstName, LastName = user.LastName, IconPath = image.Path, IconId = image.Id }; return(View(new IndnexViewModel { ProfileViewModel = model })); }