示例#1
0
 private void CriarUsuario(Usuario Usuario)
 {
     contexto.Usuarios.Add(Usuario);
     contexto.SaveChanges();
 }
示例#2
0
        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() });
        }
示例#3
0
        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);
        }