public ActionResult Logar(Usuario u) { // esta action trata o post (login) if (ModelState.IsValid) //verifica se é válido { using (MonitoriaEntities5 dc = new MonitoriaEntities5()) { var v = dc.Usuarios.Where(a => a.Perfil.Equals(u.Perfil) && a.Senha.Equals(u.Senha)).FirstOrDefault(); if (v != null) { Session["EmailLogado"] = v.Perfil.ToString(); return(View("Lockout")); } } return(View(u)); } Session["ID"] = u.ID; Session["Perfil"] = u.Perfil; if (Session["Perfil"].ToString() == "null") { return(RedirectToAction("Logar", "Home")); } if (Session["Perfil"].ToString() == "ADMIN") { return(RedirectToAction("Index", "Home")); } if (Session["Perfil"].ToString() == "Aluno") { return(RedirectToAction("Aluno", "Home")); } if (Session["Perfil"].ToString() == "Professor") { return(RedirectToAction("Professor", "Home")); } if (Session["Perfil"].ToString() == "null") { return(RedirectToAction("Logar")); } else { return(RedirectToAction("Logar", "Home", u)); } }
public ActionResult Registro(Usuario _usuario) { if (ModelState.IsValid) { using (MonitoriaEntities5 dc = new MonitoriaEntities5()) { //verifica duplicidade if (!UsuarioDAL.VerificaEmail(_usuario.Email)) { dc.Usuarios.Add(_usuario); dc.SaveChanges(); ModelState.Clear(); _usuario = null; return(RedirectToAction("Index", "Home")); } else { ViewBag.Message = "Email já cadastrado."; } } } return(View(_usuario)); }