Ejemplo n.º 1
0
 public ActionResult Register(User account)
 {
     if (account.Username == null || account.Password == null)
     {
         return(View());
     }
     if (ModelState.IsValid)
     {
         using (BSDBContext db = new BSDBContext())
         {
             var user = db.Users.FirstOrDefault(p => p.Username == account.Username);
             if (user == null)
             {
                 account.Password = HashPassword.getHash(account.Password);
                 db.Users.Add(account);
                 db.SaveChanges();
             }
             else
             {
                 ViewBag.Message = "UserName already exists" + account.Username;
                 return(View());
             }
         }
         ModelState.Clear();
         ViewBag.Message = "Successfully Registered Mr. " + account.Username;
     }
     return(RedirectToAction("Index"));
 }