Ejemplo n.º 1
0
 public ActionResult Register(Models.PasgoUser userModel)
 {
     using (PasGoEntities db = new PasGoEntities())
     {
         //Nên để thành 1 private riêng cho chức năng InsertUser
         //Chuyển thành switch
         if (ModelState.IsValid)
         {
             userModel.Salt           = CreatSalt();
             userModel.PasswordHashed = Hashed(userModel.Password, userModel.Salt);
             //Not part of the model for the current context
             var result = Convert.ToInt32(db.InsertUser(userModel.FullName, userModel.PhoneNumber, userModel.Email, true, userModel.Salt, userModel.PasswordHashed).ToList().ElementAt(0));
             if (result == 0)
             {
                 TempData["Failed"] = "Đã có người sử dụng số điện thoại này, vui lòng nhập số điện thoại khác.";
                 return(View("Register", userModel));
             }
             if (result == 1)
             {
                 TempData["Failed"] = "Đã có người sử dụng Email này, vui lòng nhập Email khác.";
                 return(View("Register", userModel));
             }
             TempData["Success"] = "Đăng ký thành công";
         }
         else
         {
             TempData["Failed"] = "Đăng ký thất bại";
             return(View("Register", userModel));
         }
     }
     ModelState.Clear();
     return(View("Register", new PasgoUser()));
 }