Ejemplo n.º 1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", CustomerValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         // Attempt to register the user
         MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
         if (createStatus == MembershipCreateStatus.Success)
         { // On success create a new customer data
             MembershipUser newUser   = MembershipService.GetUser(model.UserName, false);
             string         newUserID = newUser.ProviderUserKey.ToString();
             string         dtStamp   = DateTime.Now.ToString();
             string         accountNo = Guid.NewGuid().ToString();
             var            dbATM     = new ATMEntities();
             var            customer  = new customer
             {
                 idCustomer = newUserID,
                 firstName  = model.FirstName,
                 lastName   = model.LastName,
                 account    = accountNo,
                 cDate      = dtStamp
             };
             dbATM.customers.AddObject(customer);
             dbATM.SaveChanges();
             FormsService.SignIn(model.UserName, false);
             Session.Add("accountNumber", accountNo);
             TempData["justRegistered"] = "Y";
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("", CustomerValidation.ErrorCodeToString(createStatus));
         }
     }
     ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
     return(View(model));
 }