public void AddCarts()
 {
     for (int i = 0; i < 5; i++)
     {
         ShoppingCart cart = new ShoppingCart();
         repository.AddEntity(cart);
     }
 }
示例#2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var u = await userManager.FindByNameAsync(model.UserName);

                if (!(u is null))
                {
                    ViewBag.UserName = $"Username {model.UserName} already in use";
                    return(View());
                }
                u = await userManager.FindByEmailAsync(model.Email);

                if (!(u is null))
                {
                    ViewBag.Email = $"Email {model.Email} already in use";
                    return(View());
                }

                ShoppingCart shoppingCart = new ShoppingCart();
                shoppingCartRepository.AddEntity(shoppingCart);

                var user = new User {
                    UserName       = model.UserName,
                    Email          = model.Email,
                    Name           = model.Name,
                    LastName       = model.LastName,
                    Info           = model.Info,
                    ShoppingCartId = shoppingCart.Id,
                    Active         = true
                };
                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    /*Para el login con email
                     * var token = await userManager.GenerateEmailConfirmationTokenAsync(user);
                     * var confirmationLink = Url.Action("ConfirmEmail", "Account",
                     *  new { userId = user.Id, token = token }, Request.Scheme);
                     * logger.Log(LogLevel.Warning, confirmationLink);
                     * return View("RegistrationSuccessfulView");
                     * //*/

                    await signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("index", "home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", errorMessage: error.Description);
                    }
                }
            }
            return(View(model));
        }