public async Task <IActionResult> OnPostUser() { if (!ModelState.IsValid) { return(Page()); } var user = _ctx.Users.FirstOrDefault(x => x.Id == GetUserId()); user.PhoneNumber = AddressInput.PhoneNumber; var address = new Address { Address1 = AddressInput.Address1, Address2 = AddressInput.Address2, City = AddressInput.City, Country = AddressInput.Country, PostCode = AddressInput.PostCode }; user.Addresses.Add(address); await _ctx.SaveChangesAsync(); var mark = GetCartUserMark(); await _setCartAddress.Do(new SetCartAddress.Request { AddressId = address.Id, UserMark = mark }); return(RedirectToPage("/Checkout/Payment")); }
public async Task <IActionResult> OnPostAsync( [FromServices] SetCartAddress setCartAddress, [FromServices] UserManager <ApplicationUser> userManager, [FromServices] SignInManager <ApplicationUser> signInManager) { var user = new ApplicationUser { FirstName = Input.FirstName, LastName = Input.LastName, UserName = Input.Email, Email = Input.Email }; foreach (var item in userManager.PasswordValidators) { var password = await item.ValidateAsync(userManager, user, Input.Password); if (!password.Succeeded) { foreach (var error in password.Errors) { ModelState.AddModelError("Input.Password", string.Format("[{0}] - {1}", error.Code, error.Description)); } } } if (!ModelState.IsValid) { return(Page()); } var address = new Address { Address1 = Input.Address1, Address2 = Input.Address2, City = Input.City, PostCode = Input.PostCode, }; user.Addresses.Add(address); var result = await userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await userManager.AddClaimAsync(user, new Claim("type", "user")); await signInManager.SignInAsync(user, false); await setCartAddress.Do(new SetCartAddress.Request { UserMark = GetCartUserMark(), AddressId = address.Id }); return(RedirectToPage("/Checkout/Payment")); } return(RedirectToPage("/Index")); }
public async Task <IActionResult> OnPostAsync( [FromServices] ApplicationDbContext ctx, [FromServices] UserManager <ApplicationUser> userManager, [FromServices] SignInManager <ApplicationUser> signInManager, [FromServices] OneOffPayment payment, [FromServices] SetCartAddress setCartAddress, [FromServices] CreateOrder createOrder) { if (!Input.RequestPayment) { ModelState.ClearValidationState("Input.PayerName"); ModelState.ClearValidationState("Input.PayerEmail"); ModelState.MarkFieldValid("Input.PayerName"); ModelState.MarkFieldValid("Input.PayerEmail"); } var user = new ApplicationUser { FirstName = Input.FirstName, LastName = Input.LastName, UserName = Input.Email, Email = Input.Email }; foreach (var item in userManager.PasswordValidators) { var password = await item.ValidateAsync(userManager, user, Input.Password); if (!password.Succeeded) { foreach (var error in password.Errors) { ModelState.AddModelError("Input.Password", string.Format("[{0}] - {1}", error.Code, error.Description)); } } } if (!ModelState.IsValid) { return(Page()); } var address = new Address { Address1 = Input.Address1, Address2 = Input.Address2, City = Input.City, PostCode = Input.PostCode, }; user.Addresses.Add(address); var result = await userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await userManager.AddClaimAsync(user, new Claim("type", "superuser")); await signInManager.SignInAsync(user, false); await new CreateAccount(ctx, _emailSender) .Do(new CreateAccount.Request { UserId = user.Id, Input = new CreateAccount.BusinessRegisterViewModel { CompanyName = Input.CompanyName, RegistrationNumber = "", CompanyVAT = "", TermAccount = false, Address1 = Input.Address1, Address2 = Input.Address2, City = Input.City, PostCode = Input.PostCode, } }); await setCartAddress.Do(new SetCartAddress.Request { UserMark = GetCartUserMark(), AddressId = address.Id }); if (Input.RequestPayment) { var PaymentReference = Guid.NewGuid().ToString(); var order = await createOrder.Do(new CreateOrder.Request { UserMark = (user.Id, GetSessionId()), PayementReference = PaymentReference, });