public ActionResult Novo() { var StatusServico = new StatusServico(); var TipoServico = new TipoServico(); var ClienteServico = new ClienteServico(); var UsuarioServico = new UsuarioServico(); var model = new Visita(); if (ModelState.IsValid) { try { if (!_servico.PermissaoEditar(UsuarioId)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Usuário sem Permissão!")); //return RedirectToAction("Index", "Login"); } model = _servico.ObterPorId(1); model.Data = DateTime.Now.Date; model.ClienteId = 1; model.StatusId = 1; model.TipoId = 1; model.UsuarioId = UsuarioId; model.Anexo = ""; model.Contato = ""; model.Dcto = ""; model.Descricao = ""; model.FormaPagto = ""; model.HoraFim = TimeSpan.Zero; model.HoraInicio = TimeSpan.Zero; model.Id = 0; model.TotalHoras = 0; model.Valor = 0; model.Versao = ""; model.ListaTipos = TipoServico.ListarVisitas(""); model.ListaStatus = StatusServico.ListarVisitas(""); model.ListaClientes = ClienteServico.Listar(model.UsuarioId, ""); model.ListaUsuarios = UsuarioServico.Listar(""); return(View(model)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); ViewBag.Alerta = "Usuário sem permissão"; return(View(model)); } } else { return(View(model)); } }
public ActionResult Alterar(int id) { var StatusServico = new StatusServico(); var TipoServico = new TipoServico(); var ClienteServico = new ClienteServico(); var UsuarioServico = new UsuarioServico(); var model = _servico.ObterPorId(id); if (ModelState.IsValid) { try { if (!_servico.PermissaoEditar(UsuarioId)) { return(RedirectToAction("Index", "Login")); } model.ListaTipos = TipoServico.ListarVisitas(""); model.ListaStatus = StatusServico.ListarVisitas(""); model.ListaClientes = ClienteServico.Listar(UsuarioId, ""); model.ListaUsuarios = UsuarioServico.Listar(""); return(View(model)); } catch (Exception ex) { //ModelState.AddModelError("", ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message)); //ViewBag.Alerta = "Usuário sem permissão"; //return View(model); } } else { return(View(model)); } }