Exemple #1
0
        private static IList<User> CreateUsers(DealsContext context)
        {
            var users = new List<User>();

            for (int i = 0; i < 10; i++)
            {
                var user = new User
                {
                    UserId = i,
                    Username = string.Format("User{0}", i),
                    EmailAddress = string.Format("user{0}@email.com", i),
                    AddressLine1 = "addressline1",
                    State = "state",
                    City = "city",
                    Street = "street",
                    FirstName = "firstname",
                    LastName = "lastname",
                    ZipCode = "zip"
                };

                users.Add(user);
                context.Users.Add(user);
            }

            return users;
        }
Exemple #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                    using (var context = new DealsContext())
                    {
                        var user = new User
                        {
                            Username = model.UserName,
                            EmailAddress = model.UserName
                        };

                        context.Users.Add(user);
                        context.SaveChanges();
                    }

                    WebSecurity.Login(model.UserName, model.Password);

                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }