Set login page by user profile

0

Good afternoon guys, I need your help.

I have two access profiles to my system. "Master-IT" and "Developer"

This is my system login controller

[HttpPost]
        public ActionResult Index(Usuario usr)
        {
            if (ModelState.IsValid)
            {
                usr = _usuarioService.GetUsuarioCentroNaoRemovido(usr.Email, usr.Senha);

                if (usr != null)
                {

                    if (usr.Removido == 1)
                    {
                        var hhospitais = _hospitalService.GetAll().Select(s => new { HosppitalId = s.CentroId, Descricao = $"{s.CentroId} - {s.Nome}" });
                        ViewBag.Hospitais = new SelectList(hhospitais, "HospitalId", "Descricao", "0");

                        ModelState.AddModelError("UserNotFound", "Usuário bloqueado.");
                        return View();
                    }

                    var hospitaisLista = UsuarioCentroService.GetUsuarioCentrosByUsuario(usr.UsuarioId);
                    usr.Centros = hospitaisLista.ToList();
                    var permissoes = _permissoesService.GetPermissaoByUser(usr.UsuarioId).Select(s => s.Nome).ToList();
                    CriarCookie(usr);
                    CreateTicket(usr, permissoes);

                    _usuarioService.Dispose();
                    return RedirectToAction("Index", "Cadastro", new { area = "Formulario" });
                }
            }

            var hospitais = _hospitalService.GetAll().Select(s => new { HospitalId = s.CentroId, Descricao = $"{s.CentroId} - {s.Nome}" });
            ViewBag.Hospitais = new SelectList(hospitais, "HospitalId", "Descricao", "0");

            ModelState.AddModelError("UserNotFound", "Usuario não encontrado!");
            return View();
        }

My request for help is as follows, I need to check which profile you are accessing

If Master-TI enters this view return RedirectToAction("Index", "Cadastro", new { area = "Formulario" });

If Developer enters this view return RedirectToAction("Desenvolvimento", "Cadastro", new { area = "Formulario" });

I tried to use the User.IsInRole ("Master-TI") doing an if on return only that did not work

    
asked by anonymous 12.04.2018 / 21:59

1 answer

0

I've managed to resolve it.

public async Task<ActionResult> Index()
        {
            if (!Cookies.Exists("hid"))
                return RedirectToAction("Index", "Login", new { area = "Entrar" });

            var hospitalId = int.Parse(Cookies.GetCookie("hid"));
            var lista = await _cadastroService.GetLista(hospitalId);
            if (User.IsInRole("Genérico"))
            {
                return RedirectToAction("Cadastro", "Cadastro", new { area = "Formulario" });
            }
            else
            {
                return View(lista);
            }
        }
    
12.04.2018 / 22:46