public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Intento de registrar al usuario
                try
                {
                    Address addressModel = new Address();
                    addressModel.Street = model.Street;
                    addressModel.Number = Convert.ToInt32(model.Number);
                    addressModel.City = model.City;
                    addressModel.State = model.State;
                    addressModel.ZipCode = Convert.ToInt32(model.ZipCode);
                    addressModel.AddressTypeId = 1;
                    addressModel.IsAddressActive = true;

                    Client clientModel = new Client();
                    clientModel.Email = model.UserName;
                    clientModel.Password = model.Password;
                    clientModel.FirstName = model.FirstName;
                    clientModel.LastName = model.LastName;
                    clientModel.RFC = model.RFC;
                    clientModel.TelephoneNumber = model.Telephone;
                    clientModel.BillingAddress = addressModel;
                    clientModel.ShippingAddress = addressModel;
                    clientModel.IsClientActive = true;
                    clientModel.ClientTypeId = 1;
                    client.AddClient(clientModel);
                    //client.AuthenticateUser(model.UserName, model.Password,persistCookie:false);
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            return View(model);
        }
예제 #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Intento de registrar al usuario
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            return View(model);
        }