public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); ResponsavelModel responsavel = new ResponsavelModel(); responsavel.nome = model.UserName; responsavel.email = model.Email; responsavel.sobrenome = model.UserName; gResponsavel.Inserir(responsavel); //Membership usuario = Membership.GetUser(); Roles.AddUserToRole(model.UserName, "Responsavel"); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create(ResponsavelModel responsavel) { if (ModelState.IsValid) { MembershipUser usuario = Membership.GetUser(); int idCodigo = retornarIdResponsavel(usuario.ToString()); if (idCodigo != -1) { Roles.AddUserToRole(usuario.ToString(), "Responsavel"); responsavel.id_Responsavel = idCodigo; gResponsavel.Inserir(responsavel); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } return(View()); }