Example #1
0
        public ActionResult ConfirmOrder(CheckoutConfirmOrderViewModel viewModel)
        {
            StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow;
            Cart cart = config.StoreFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            if (!cart.CartIsValidForCheckout(this))
            {
                return(RedirectToAction("Index", "Cart"));
            }

            if (!cart.StatusStartedCheckout)
            {
                return(RedirectToAction("Index"));
            }
            if (!cart.StatusSelectedLogInOrGuest)
            {
                return(RedirectToAction("LogInOrGuest"));
            }

            cart = cart.ValidateCartAndSave(this);

            if (!cart.StatusCompletedDeliveryInfo)
            {
                return(RedirectToAction("DeliveryInfo"));
            }
            if (!cart.StatusSelectedDeliveryMethod)
            {
                return(RedirectToAction("DeliveryMethod"));
            }
            if (!cart.StatusPaymentInfoConfirmed)
            {
                return(RedirectToAction("PaymentInfo"));
            }

            if (config.CheckoutConfirmOrderWebForm != null)
            {
                FormProcessorExtensions.ValidateFields(this, config.CheckoutConfirmOrderWebForm);
            }

            if (ModelState.IsValid)
            {
                WebFormResponse webFormResponse = cart.ConfirmOrderProcessWebForm(this);
                if (webFormResponse != null)
                {
                    cart.ConfirmOrderWebFormResponseId = webFormResponse.WebFormResponseId;
                    GStoreDb.Carts.Update(cart);
                    GStoreDb.SaveChanges();
                }

                return(cart.ProcessOrderAndPayment(this));
            }

            viewModel.UpdateForRepost(config, cart, RouteData.Action());
            return(View("ConfirmOrder", viewModel));
        }
Example #2
0
        public ActionResult DeliveryMethod(CheckoutDeliveryMethodShippingViewModel viewModel)
        {
            StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow;
            Cart cart = config.StoreFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            if (!cart.CartIsValidForCheckout(this))
            {
                return(RedirectToAction("Index", "Cart"));
            }

            if (!cart.StatusStartedCheckout)
            {
                return(RedirectToAction("Index"));
            }
            if (!cart.StatusSelectedLogInOrGuest)
            {
                return(RedirectToAction("LogInOrGuest"));
            }

            cart = cart.ValidateCartAndSave(this);

            if (!cart.StatusCompletedDeliveryInfo)
            {
                return(RedirectToAction("DeliveryInfo"));
            }

            if (config.CheckoutDeliveryMethodWebForm != null)
            {
                FormProcessorExtensions.ValidateFields(this, config.CheckoutDeliveryMethodWebForm);
            }

            if (ModelState.IsValid)
            {
                WebFormResponse webFormResponse = cart.DeliveryMethodProcessWebForm(this);
                if (webFormResponse != null)
                {
                    cart.DeliveryInfoShipping.DeliveryMethodWebFormResponseId = webFormResponse.WebFormResponseId;
                }
                cart.DeliveryInfoShipping.ShippingDeliveryMethod = viewModel.ShippingDeliveryMethod;
                cart.DeliveryInfoShipping.ShippingDeliveryMethod = viewModel.ShippingDeliveryMethod;
                cart.StatusSelectedDeliveryMethod = true;
                GStoreDb.Carts.Update(cart);
                GStoreDb.SaveChanges();

                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Checkout, UserActionActionEnum.Checkout_SelectedDeliveryMethod, "", true, cartId: cart.CartId);

                return(RedirectToAction("PaymentInfo"));
            }
            viewModel.UpdateForRepost(config, cart, RouteData.Action());
            return(View("DeliveryMethod", viewModel));
        }
Example #3
0
        public virtual ActionResult SubmitForm()
        {
            this._logActionsAsPageViews = true;
            CheckAccessAndRedirect();
            Page page = CurrentPageOrThrow;

            if (page.WebForm == null)
            {
                return(HttpBadRequest("There is no form for page '" + page.Name + "' [" + page.PageId + "]"));
            }
            if (!page.WebForm.IsActiveBubble())
            {
                return(HttpBadRequest("Form is inactive for page '" + page.Name + "' [" + page.PageId + "]"));
            }

            if (FormProcessorExtensions.ProcessWebForm(this, page.WebForm, page, false, null))
            {
                string messageTitle = (string.IsNullOrEmpty(page.WebFormThankYouTitle) ? "Your form has been Sent!" : page.WebFormThankYouTitle);
                string messageBody  = (string.IsNullOrEmpty(page.WebFormThankYouMessage) ? "Thank you for your information, we will get back to you soon!" : page.WebFormThankYouMessage);

                messageBody  = messageBody.ReplaceVariables(CurrentClientOrNull, CurrentStoreFrontConfigOrThrow, CurrentUserProfileOrNull, CurrentPageOrNull, string.Empty);
                messageTitle = messageTitle.ReplaceVariables(CurrentClientOrNull, CurrentStoreFrontConfigOrThrow, CurrentUserProfileOrNull, CurrentPageOrNull, string.Empty);

                ModelState.Clear();

                AddUserMessage(messageTitle.ToHtml(), messageBody, UserMessageType.Success);
                if (page.WebFormSuccessPageId == null)
                {
                    return(Redirect(Url.GStoreLocalUrl("/")));
                }
                Page redirectPageTarget = CurrentStoreFrontOrThrow.Pages.SingleOrDefault(p => p.PageId == page.WebFormSuccessPageId.Value);
                if (redirectPageTarget == null)
                {
                    throw new ApplicationException("Success Page not found. page.WebFormSuccessPageId: " + page.WebFormSuccessPageId);
                }
                if (redirectPageTarget.IsActiveBubble())
                {
                    return(Redirect(redirectPageTarget.UrlResolved(Url)));
                }
                return(Redirect(Url.GStoreLocalUrl("/")));
            }
            //re-display form if process error
            AddUserMessage("Form Error", "There was a problem with your form values. Please correct the errors below.", UserMessageType.Danger);
            return(Display());
        }
Example #4
0
        public ActionResult PaymentInfo(CheckoutPaymentInfoViewModel viewModel)
        {
            StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow;
            Cart cart = config.StoreFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            if (!cart.CartIsValidForCheckout(this))
            {
                return(RedirectToAction("Index", "Cart"));
            }

            if (!cart.StatusStartedCheckout)
            {
                return(RedirectToAction("Index"));
            }
            if (!cart.StatusSelectedLogInOrGuest)
            {
                return(RedirectToAction("LogInOrGuest"));
            }

            cart = cart.ValidateCartAndSave(this);

            if (!cart.StatusCompletedDeliveryInfo)
            {
                return(RedirectToAction("DeliveryInfo"));
            }
            if (!cart.StatusSelectedDeliveryMethod)
            {
                return(RedirectToAction("DeliveryMethod"));
            }

            if (config.CheckoutPaymentInfoWebForm != null)
            {
                FormProcessorExtensions.ValidateFields(this, config.CheckoutPaymentInfoWebForm);
            }

            if (ModelState.IsValid)
            {
                WebFormResponse webFormResponse = cart.PaymentInfoProcessWebForm(this);
                if (config.PaymentMethod_PayPal_Enabled)
                {
                    return(Payment_PayPalStartPayment(viewModel, webFormResponse));
                }


                //payment with pay after order/no automated processing
                CartPaymentInfo cartPaymentInfo = null;
                if (cart.CartPaymentInfo == null)
                {
                    cartPaymentInfo = GStoreDb.CartPaymentInfos.Create();
                    cartPaymentInfo.SetDefaults(CurrentUserProfileOrNull);
                    cartPaymentInfo.Client           = CurrentClientOrThrow;
                    cartPaymentInfo.ClientId         = cartPaymentInfo.Client.ClientId;
                    cartPaymentInfo.StoreFront       = CurrentStoreFrontOrThrow;
                    cartPaymentInfo.StoreFrontId     = cartPaymentInfo.StoreFront.StoreFrontId;
                    cartPaymentInfo.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
                    cartPaymentInfo.EndDateTimeUtc   = DateTime.UtcNow.AddYears(100);
                    cartPaymentInfo.Cart             = cart;
                    cartPaymentInfo.CartId           = cart.CartId;
                    if (webFormResponse != null)
                    {
                        cartPaymentInfo.WebFormResponseId = webFormResponse.WebFormResponseId;
                    }

                    cartPaymentInfo = GStoreDb.CartPaymentInfos.Add(cartPaymentInfo);
                }
                else
                {
                    cartPaymentInfo = cart.CartPaymentInfo;
                    if (webFormResponse != null)
                    {
                        cartPaymentInfo.WebFormResponseId = webFormResponse.WebFormResponseId;
                    }
                    cartPaymentInfo = GStoreDb.CartPaymentInfos.Update(cartPaymentInfo);
                }

                //add/remove/etc
                cart.StatusPaymentInfoConfirmed = true;
                GStoreDb.Carts.Update(cart);
                GStoreDb.SaveChanges();

                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Checkout, UserActionActionEnum.Checkout_ConfirmedPaymentInfo, "", true, cartId: cart.CartId);

                return(RedirectToAction("ConfirmOrder"));
            }

            viewModel.UpdateForRepost(config, cart, RouteData.Action());
            return(View("PaymentInfo", viewModel));
        }
Example #5
0
        public ActionResult DeliveryInfoShipping(CheckoutDeliveryInfoShippingViewModel viewModel)
        {
            StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow;
            Cart cart = config.StoreFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            if (!cart.CartIsValidForCheckout(this))
            {
                return(RedirectToAction("Index", "Cart"));
            }

            if (!cart.StatusStartedCheckout)
            {
                return(RedirectToAction("Index"));
            }
            if (!cart.StatusSelectedLogInOrGuest)
            {
                return(RedirectToAction("LogInOrGuest"));
            }

            cart = cart.ValidateCartAndSave(this);

            if (cart.AllItemsAreDigitalDownload)
            {
                return(RedirectToAction("DeliveryInfo"));
            }

            //check if custom form is valid
            if (config.CheckoutDeliveryInfoShippingWebForm != null)
            {
                FormProcessorExtensions.ValidateFields(this, config.CheckoutDeliveryInfoShippingWebForm);
            }

            if (ModelState.IsValid)
            {
                WebFormResponse webFormResponse = cart.DeliveryInfoShippingProcessWebForm(this);

                DeliveryInfoShipping info = null;
                if (cart.DeliveryInfoShipping == null)
                {
                    info = GStoreDb.DeliveryInfoShippings.Create();
                    info.SetDefaults(CurrentUserProfileOrNull);
                    info.Client           = CurrentClientOrThrow;
                    info.ClientId         = info.Client.ClientId;
                    info.StoreFront       = CurrentStoreFrontOrThrow;
                    info.StoreFrontId     = info.StoreFront.StoreFrontId;
                    info.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
                    info.EndDateTimeUtc   = DateTime.UtcNow.AddYears(100);
                    info.Cart             = cart;
                    info.CartId           = cart.CartId;

                    info.AdddressL1   = viewModel.AdddressL1;
                    info.AdddressL2   = viewModel.AdddressL2;
                    info.EmailAddress = viewModel.EmailAddress;
                    info.FullName     = viewModel.FullName;
                    info.City         = viewModel.City;
                    info.State        = viewModel.State;
                    info.PostalCode   = viewModel.PostalCode;
                    info.CountryCode  = viewModel.CountryCode.Value;
                    if (webFormResponse != null)
                    {
                        info.WebFormResponseId = webFormResponse.WebFormResponseId;
                    }
                    info = GStoreDb.DeliveryInfoShippings.Add(info);
                }
                else
                {
                    info              = cart.DeliveryInfoShipping;
                    info.AdddressL1   = viewModel.AdddressL1;
                    info.AdddressL2   = viewModel.AdddressL2;
                    info.EmailAddress = viewModel.EmailAddress;
                    info.FullName     = viewModel.FullName;
                    info.City         = viewModel.City;
                    info.State        = viewModel.State;
                    info.PostalCode   = viewModel.PostalCode;
                    info.CountryCode  = viewModel.CountryCode.Value;
                    if (webFormResponse != null)
                    {
                        info.WebFormResponseId = webFormResponse.WebFormResponseId;
                    }
                    info = GStoreDb.DeliveryInfoShippings.Update(info);
                }

                cart.DeliveryInfoShipping = info;
                cart.Email    = viewModel.EmailAddress;
                cart.FullName = viewModel.FullName;
                cart.StatusCompletedDeliveryInfo = true;
                GStoreDb.Carts.Update(cart);
                GStoreDb.SaveChanges();

                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Checkout, UserActionActionEnum.Checkout_CompletedDeliveryInfo, "", true, cartId: cart.CartId);

                return(RedirectToAction("DeliveryMethod"));
            }

            viewModel.UpdateForRepost(config, cart, RouteData.Action());
            return(View("DeliveryInfoShipping", viewModel));
        }
Example #6
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            StoreFront storeFront = CurrentStoreFrontOrNull;
            StoreFrontConfiguration storeFrontConfig = CurrentStoreFrontConfigOrNull;

            if ((storeFront != null) && (storeFrontConfig != null) && (storeFrontConfig.RegisterWebForm != null) && storeFrontConfig.RegisterWebForm.IsActiveBubble())
            {
                FormProcessorExtensions.ValidateFields(this, storeFrontConfig.RegisterWebForm);
            }

            if (ModelState.IsValid)
            {
                var user = new AspNetIdentityUser(model.Email)
                {
                    UserName = model.Email, Email = model.Email
                };
                user.TwoFactorEnabled = Settings.IdentityEnableTwoFactorAuth;
                IdentityResult result = null;
                try
                {
                    result = await UserManager.CreateAsync(user, model.Password);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException exDbEx)
                {
                    foreach (System.Data.Entity.Validation.DbEntityValidationResult valResult in exDbEx.EntityValidationErrors)
                    {
                        ICollection <System.Data.Entity.Validation.DbValidationError> valErrors = valResult.ValidationErrors;
                        foreach (System.Data.Entity.Validation.DbValidationError error in valErrors)
                        {
                            ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                        }
                    }
                    return(View(model));
                }
                catch (Exception ex)
                {
                    string error = ex.ToString();
                    throw;
                }
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : true, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771

                    IGstoreDb   ctx        = GStoreDb;
                    UserProfile newProfile = ctx.UserProfiles.Create();
                    newProfile.UserId   = user.Id;
                    newProfile.UserName = user.UserName;
                    newProfile.Email    = user.Email;
                    newProfile.FullName = model.FullName;
                    newProfile.NotifyOfSiteUpdatesToEmail = model.NotifyOfSiteUpdates;
                    newProfile.SendMoreInfoToEmail        = model.SendMeMoreInfo;
                    newProfile.SignupNotes           = model.SignupNotes;
                    newProfile.NotifyAllWhenLoggedOn = true;
                    newProfile.IsPending             = false;
                    newProfile.Order            = CurrentStoreFrontOrThrow.UserProfiles.Max(up => up.Order) + 10;
                    newProfile.EntryDateTime    = Session.EntryDateTime().Value;
                    newProfile.EntryRawUrl      = Session.EntryRawUrl();
                    newProfile.EntryReferrer    = Session.EntryReferrer();
                    newProfile.EntryUrl         = Session.EntryUrl();
                    newProfile.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
                    newProfile.EndDateTimeUtc   = DateTime.UtcNow.AddYears(100);
                    newProfile.StoreFrontId     = CurrentStoreFrontOrThrow.StoreFrontId;
                    newProfile.StoreFront       = CurrentStoreFrontOrThrow;
                    newProfile.ClientId         = this.CurrentClientOrThrow.ClientId;
                    newProfile.Client           = this.CurrentClientOrThrow;
                    newProfile = ctx.UserProfiles.Add(newProfile);
                    ctx.SaveChanges();

                    ctx.UserName          = user.UserName;
                    ctx.CachedUserProfile = null;


                    string customFields = string.Empty;
                    if (storeFrontConfig != null && storeFrontConfig.RegisterWebForm != null && storeFrontConfig.RegisterWebForm.IsActiveBubble())
                    {
                        FormProcessorExtensions.ProcessWebForm(this, storeFrontConfig.RegisterWebForm, null, true, null);
                        customFields = FormProcessorExtensions.BodyTextCustomFieldsOnly(this, storeFrontConfig.RegisterWebForm);
                    }

                    bool confirmResult = SendEmailConfirmationCode(user.Id, newProfile);

                    ctx.LogSecurityEvent_NewRegister(this.HttpContext, RouteData, newProfile, this);
                    string notificationBaseUrl = Url.Action("Details", "Notifications", new { id = "" });
                    CurrentStoreFrontOrThrow.HandleNewUserRegisteredNotifications(this.GStoreDb, Request, newProfile, notificationBaseUrl, true, true, customFields);

                    if (storeFront != null)
                    {
                        Cart cart = storeFront.GetCart(Session.SessionID, null);
                        cart = storeFront.MigrateCartToProfile(GStoreDb, cart, newProfile, this);
                        storeFront.MigrateOrdersToNewProfile(GStoreDb, newProfile, this);
                    }

                    if (Settings.IdentityEnableNewUserRegisteredBroadcast && CurrentClientOrThrow.EnableNewUserRegisteredBroadcast)
                    {
                        string title   = model.FullName;
                        string message = "Newly registered!";
                        Microsoft.AspNet.SignalR.IHubContext hubCtx = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <GStoreWeb.Hubs.NotifyHub>();
                        hubCtx.Clients.All.addNewMessageToPage(title, message);
                    }

                    if (model.CheckingOut ?? false)
                    {
                        return(RedirectToAction("LoginOrGuest", "Checkout", new { ContinueAsLogin = true }));
                    }

                    if (storeFrontConfig != null && storeFrontConfig.RegisterSuccess_PageId.HasValue)
                    {
                        return(Redirect(storeFrontConfig.RegisterSuccessPage.UrlResolved(this.Url)));
                    }
                    return(RedirectToAction("RegisterSuccess"));
                }
                AddErrors(result);
            }

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