public ActionResult CreateStepThree(Endereco endereco) { try { if (ModelState.IsValid) { Usuario usuario = (Usuario)Session["User"]; usuario.ContaAtiva = true; endereco.Usuario = usuario; enderecoServico.SaveEndereco(endereco); string perfil = "Cliente"; if (usuario.IsAdmin == true) { perfil = "Gerente"; } FormsAuthentication.SignOut(); var ticket = FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, usuario.Email, DateTime.Now, DateTime.Now.AddHours(12), false, perfil)); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticket); Response.Cookies.Add(cookie); Session["UserName"] = usuario.Nome.Split(' ')[0]; } else { return(View()); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult GravarEndereco(Endereco endereco) { try { if (ModelState.IsValid) { Usuario usuario = (Usuario)Session["User"]; endereco.UsuarioId = usuario.Id; enderecoServico.SaveEndereco(endereco); } else { return(View()); } return(RedirectToAction("MeusEnderecos")); } catch (Exception excecao) { ViewBag.Error = excecao.Message; return(View("MeusEnderecos")); } }