public IActionResult Edit(int id, HardwareDeSalaModel hardware) { var idUsuario = _usuarioService.RetornLoggedUser((ClaimsIdentity)User.Identity).UsuarioModel.Id; ViewBag.Organizacoes = _organizacaoService.GetByIdUsuario(idUsuario); ViewBag.Blocos = _blocoService.GetByIdOrganizacao(hardware.Organizacao); ViewBag.Salas = _salaService.GetByIdBloco(hardware.Bloco); ViewBag.tipoHardware = new SelectList(_tipoHardwareService.GetAll(), "Id", "Descricao"); try { if (string.IsNullOrEmpty(hardware.Ip) && hardware.TipoHardwareId == TipoHardwareModel.CONTROLADOR_DE_SALA) { ModelState.AddModelError("Ip", "Adicione um endereço IP"); return(View(hardware)); } if (ModelState.IsValid) { if (_hardwareService.Update(hardware, idUsuario)) { TempData["mensagemSucesso"] = "Hardware atualizado com sucesso"; } else { TempData["mensagemErro"] = "Houve um problema ao atualizar hardware, tente novamente em alguns minutos!"; } } } catch (ServiceException se) { TempData["mensagemErro"] = se.Message; } return(RedirectToAction(nameof(Index))); }
public ActionResult Put(int id, [FromBody] HardwareDeSalaModel hardwareModel, int idUser) { try { if (string.IsNullOrEmpty(hardwareModel.Ip) && hardwareModel.TipoHardwareId == TipoHardwareModel.CONTROLADOR_DE_SALA) { ModelState.AddModelError("Ip", "Adicione um endereço IP"); } if (_service.Update(hardwareModel, idUser)) { return(Ok()); } return(BadRequest()); } catch (ServiceException e) { return(StatusCode(500, e.Message)); } }