private void CriarUsuario(Usuario Usuario) { contexto.Usuarios.Add(Usuario); contexto.SaveChanges(); }
public ActionResult JsonRegistrar(Usuario model) { if (ModelState.IsValid) { try { CriarUsuario(model); FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false); return Json(new { success = true }); } catch(Exception ex) { ModelState.AddModelError("", ex.Message); } } // If we got this far, something failed return Json(new { errors = ModelState.ToArray() }); }
public ActionResult Registrar(Usuario model) { if (ModelState.IsValid) { try { CriarUsuario(model); FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false); return RedirectToAction("Index", "Home"); } catch(Exception ex) { ModelState.AddModelError("", ex.Message); } } // If we got this far, something failed, redisplay form return View(model); }