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("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }
        public void Register_Post_ReturnsViewIfRegistrationFails()
        {
            // Arrange
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("Username already exists. Please enter a different user name.", controller.ModelState[""].Errors[0].ErrorMessage);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
        public void Register_Post_ReturnsRedirectOnSuccess()
        {
            // Arrange
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.AreEqual("Home", redirectResult.RouteValues["controller"]);
            Assert.AreEqual("Index", redirectResult.RouteValues["action"]);
        }
        public void Register_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // Arrange
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "Dummy error message.");

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
        public ActionResult Register(RegisterModel model)
        {
            //Clientes
            TB_Cliente newCliente = new TB_Cliente();
            newCliente.cTelefono = Request.Form["Telefono"].ToString();
            newCliente.cDireccion = Request.Form["Direccion"].ToString();

            if (Request.Form["codDepartamento"] != null)
            {
                newCliente.codDepartamento = Request.Form["codDepartamento"].ToString();
            }

            if (Request.Form["codProvincia"] != null)
            {
                newCliente.codProvincia = Request.Form["codProvincia"].ToString();
            }

            if (Request.Form["codDistrito"] != null)
            {
                newCliente.codDistrito = Request.Form["codDistrito"].ToString();
            }

            if (Request.Form["dropDownTipoCliente"].Equals("1"))
            {
                newCliente.cTipCliente = "NAT";
            }
            else {
                newCliente.cTipCliente = "JUR";
            }

            //Agregar el Cliente a la tabla clientes.
            _data.TB_Clientes.InsertOnSubmit(newCliente);
               // newCliente.Pk_eCliente;
            _data.SubmitChanges();

            //Agregar el tipo de cliene segun tipo de cliente
            if (newCliente.cTipCliente.Equals("JUR")) {
                TB_PersonaJuridica newClienteJuridico = new TB_PersonaJuridica();
                newClienteJuridico.Fk_eCliente = newCliente.Pk_eCliente;
                newClienteJuridico.cRuc = Request.Form["Ruc"].ToString();
                newClienteJuridico.cRazSocial = Request.Form["RazonSocial"].ToString();

                _data.TB_PersonaJuridicas.InsertOnSubmit(newClienteJuridico);
                _data.SubmitChanges();
            }
            else if (newCliente.cTipCliente.Equals("NAT")) {
                TB_PersonaNatural newClienteNatural = new TB_PersonaNatural();
                newClienteNatural.Fk_eCliente = newCliente.Pk_eCliente;
                newClienteNatural.cDNI = Request.Form["Dni"].ToString();
                newClienteNatural.cNombres = Request.Form["Nombres"].ToString();
                newClienteNatural.cApellidos = Request.Form["Apellidos"].ToString();

                _data.TB_PersonaNaturals.InsertOnSubmit(newClienteNatural);
                _data.SubmitChanges();
            }

            //Usuario
            TB_Usuario newUsuario = new TB_Usuario();
            newUsuario.Fk_eCliente = newCliente.Pk_eCliente;
            newUsuario.cUsuario = Request.Form["UserName"].ToString();
            newUsuario.cContrasena = Request.Form["Password"].ToString();

            _data.TB_Usuarios.InsertOnSubmit(newUsuario);
            _data.SubmitChanges();

            return RedirectToAction("Logon", "Account");
        }