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 async Task <ActionResult> Create(CreateSensorTypeViewModel sensorTypeViewModel) { if (!ModelState.IsValid) { return(View(sensorTypeViewModel)); } SensorTypeDto sensorTypeDto = _mapper.Map <CreateSensorTypeViewModel, SensorTypeDto>(sensorTypeViewModel); if (sensorTypeViewModel.IconFile != null) { sensorTypeDto.IconId = await _iconManager.CreateAndGetIconId(sensorTypeViewModel.IconFile); } var res = _sensorTypeManager.Create(sensorTypeDto).Result; if (res != null) { return(ViewComponent("SensorTypeElement", _mapper.Map <SensorTypeDto, SensorTypeViewModel>(res))); } else { //ModelState.AddModelError(res.Property, res.Message); return(View(sensorTypeViewModel)); } }
public async Task <IActionResult> Create(CreateDashboardViewModel model) { if (!ModelState.IsValid) { return(View(model)); } DashboardDto dashboardDto = _mapper.Map <CreateDashboardViewModel, DashboardDto>(model); if (model.IconFile != null) { dashboardDto.IconId = await _iconManager.CreateAndGetIconId(model.IconFile); } dashboardDto.AppUserId = _userManager.GetUserId(User); var res = _dashboardManager.Create(dashboardDto).Result; if (res != null) { DashboardViewModel dashmodel = _mapper.Map <DashboardDto, DashboardViewModel>(res); 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> Update(IndnexViewModel model) { if (!ModelState.IsValid) { return(Ok()); } var user = await _userManager.GetUserAsync(User); if (model.ProfileViewModel.IconFile != null) { var id = await _iconManager.CreateAndGetIconId(model.ProfileViewModel.IconFile); user.IconId = id; } user.Email = model.ProfileViewModel.Email; user.PhoneNumber = model.ProfileViewModel.PhoneNumber; user.FirstName = model.ProfileViewModel.FirstName; user.LastName = model.ProfileViewModel.LastName; var result = _userManager.UpdateAsync(user); if (!result.Result.Succeeded) { return(BadRequest()); } return(Ok()); }