예제 #1
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            Customer cust = new Customer();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
                cust.User_Id = user.Id;
                CustomerContext context = new CustomerContext();
                user.Carts = new Cart { DateLastModified = DateTime.Now };
                user.Wishlists = new Wishlist { };
                IdentityResult result = new IdentityResult();
                try
                { result = await UserManager.CreateAsync(user, model.Password); context.Customers.Add(cust); context.SaveChanges(); }
                catch (Exception e)
                { Response.Write("" + e); }
                if (result.Succeeded)
                {

                    await SignInAsync(user, isPersistent: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account with us by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return Json(new { success = true });
                    //return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            //return View(model);
            return PartialView(model);
        }
예제 #2
0
        public async Task<ActionResult> FullRegister(FullRegisterViewModel model, string returnUrl)
        {
            CustomerContext context = new CustomerContext();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, Address = model.Address, PhoneNumber = model.CellPhone };
                Customer Customers = new Customer() { FirstName = model.FirstName, LastName = model.LastName, User_Id = user.Id };
                user.Carts = new Cart { DateLastModified = DateTime.Now};
                IQueryable<Customer> cust = context.Customers;
                var i = context.Customers.ToList().LastOrDefault();
                user.Wishlists = new Wishlist { Status = false};
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                context.Customers.Add(Customers);
                context.SaveChanges();
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                     string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                     var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                     await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            return PartialView(model);
        }