public ActionResult Create([Bind(Include = "idUser,email,password")] user user)
        {
            if (ModelState.IsValid)
            {
                db.users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Example #2
0
 public ActionResult AddOrEdit(user user)
 {
     using (DatabaseModels databaseModel = new DatabaseModels())
     {
         try
         {
             if (databaseModel.users.Any(x => x.email == user.email))
             {
                 ViewBag.ErrorMessage = "Ya existe un usuario con ese email";
                 return(View("AddOrEdit", new user()));
             }
             else
             {
                 databaseModel.users.Add(user);
                 databaseModel.SaveChanges();
                 ModelState.Clear();
                 ViewBag.SuccessMessage = "Se ha Registrado el usuario: " + user.email;
                 return(View("Login"));
             }
         }
         catch (Exception exception)
         {
             ViewBag.ErrorMessage = "Ha ocurrido un error al intentar registrar el usuario" + exception.StackTrace;
             return(View("AddOrEdit", new user()));
         }
     }
 }