Example #1
0
        /// <summary>
        /// Processes a web form for a checkout page. saves response to database and return WebFormResponse object.
        /// If no data to save, returns null.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="modelStateDictionary"></param>
        /// <param name="webForm"></param>
        /// <param name="storeFrontConfig"></param>
        /// <param name="userProfile"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static WebFormResponse ProcessWebFormForCheckout(BaseController controller, WebForm webForm, WebFormResponse oldResponseToUpdateOrNull)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            if (webForm == null)
            {
                throw new ArgumentNullException("webForm");
            }

            bool isValid = ValidateFields(controller, webForm);

            if (!controller.ModelState.IsValid || !isValid)
            {
                return(null);
            }

            string formBodyText = BuildFormBodyText(controller, webForm, null, false);
            string formSubject  = BuildFormSubject(controller, webForm, null);

            //checkout forms always go to database
            WebFormResponse response = ProcessWebForm_ToDatabase(controller, webForm, null, formSubject, formBodyText, false, oldResponseToUpdateOrNull);

            return(response);
        }
Example #2
0
        /// <summary>
        /// saves form data to database, is isRegisterPage = true, also updates user profile
        /// </summary>
        /// <param name="db"></param>
        /// <param name="modelStateDictionary"></param>
        /// <param name="webForm"></param>
        /// <param name="page"></param>
        /// <param name="userProfile"></param>
        /// <param name="request"></param>
        /// <param name="storeFrontConfiguration"></param>
        /// <param name="formSubject"></param>
        /// <param name="formBodyText"></param>
        /// <param name="isRegisterPage"></param>
        /// <returns></returns>
        private static WebFormResponse ProcessWebForm_ToDatabase(BaseController controller, WebForm webForm, Page page, string formSubject, string formBodyText, bool isRegisterPage, WebFormResponse oldResponseToUpdateOrNull)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            IGstoreDb               db                      = controller.GStoreDb;
            UserProfile             userProfile             = controller.CurrentUserProfileOrNull;
            StoreFrontConfiguration storeFrontConfiguration = controller.CurrentStoreFrontConfigOrThrow;

            WebFormResponse webFormResponse = null;

            if (oldResponseToUpdateOrNull == null)
            {
                webFormResponse = db.WebFormResponses.Create();
                webFormResponse.SetDefaults(userProfile);
            }
            else
            {
                webFormResponse = oldResponseToUpdateOrNull;
            }
            webFormResponse.StoreFrontId     = storeFrontConfiguration.StoreFrontId;
            webFormResponse.StoreFront       = storeFrontConfiguration.StoreFront;
            webFormResponse.ClientId         = storeFrontConfiguration.ClientId;
            webFormResponse.Client           = storeFrontConfiguration.Client;
            webFormResponse.PageId           = (page == null ? null : (int?)page.PageId);
            webFormResponse.Page             = page;
            webFormResponse.WebFormId        = webForm.WebFormId;
            webFormResponse.WebForm          = webForm;
            webFormResponse.IsPending        = false;
            webFormResponse.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            webFormResponse.EndDateTimeUtc   = DateTime.UtcNow.AddYears(100);
            webFormResponse.BodyText         = formBodyText;
            webFormResponse.Subject          = formSubject;

            FillWebFormResponses(controller, webFormResponse, webForm, oldResponseToUpdateOrNull);

            if (oldResponseToUpdateOrNull == null)
            {
                webFormResponse = db.WebFormResponses.Add(webFormResponse);
            }
            else
            {
                webFormResponse = db.WebFormResponses.Update(oldResponseToUpdateOrNull);
            }
            db.SaveChanges();

            if (isRegisterPage && (userProfile != null))
            {
                userProfile.RegisterWebFormResponseId = webFormResponse.WebFormResponseId;
                db.UserProfiles.Update(userProfile);
                db.SaveChangesDirect();
            }

            //for checkout page and other pages return object
            return(webFormResponse);
        }
Example #3
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 #4
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 #5
0
        /// <summary>
        /// Starts a PayPal payment and returns a redirect result to PayPal (or payment info page if an error occurs)
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        protected ActionResult Payment_PayPalStartPayment(CheckoutPaymentInfoViewModel viewModel, WebFormResponse webFormResponse)
        {
            StoreFrontConfiguration storeFrontConfig = CurrentStoreFrontConfigOrThrow;
            Cart cart = storeFrontConfig.StoreFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            Uri returnUri = new Uri(Url.Action("PayPalAccountConfirmed", null, null, Request.Url.Scheme));
            Uri cancelUri = new Uri(Url.Action("PayPalCanceled", null, null, Request.Url.Scheme));

            PayPalPaymentClient paypalClient = new PayPalPaymentClient();

            PayPalPaymentData response;

            try
            {
                response = paypalClient.StartPayPalPayment(storeFrontConfig, cart, returnUri, cancelUri);
            }
            catch (PayPalExceptionOAuthFailed exOAuth)
            {
                string message = "Sorry, this store's configuration for PayPal OAuth is not operational. Please contact us for other payment options."
                                 + (exOAuth.IsSandbox ? "\nError in Sandbox Config." : "\nError in Live Config");
                AddUserMessage("PayPal Error", message, UserMessageType.Danger);

                if (CurrentUserProfileOrNull != null && CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                {
                    string adminMessage = exOAuth.ToString()
                                          + "\n\nHTTP Response:\n" + exOAuth.ResponseString
                                          + "\n\nHTTP Headers:\n" + exOAuth.ResponseHeaders;
                    AddUserMessage("PayPal Error (admin info)", "Error " + adminMessage, UserMessageType.Danger);
                }

                return(RedirectToAction("PaymentInfo"));
            }
            catch (PayPalExceptionCreatePaymentFailed exPaymentFailed)
            {
                string message = "Sorry, there was an error sending your order to PayPal for payment. Please contact us for other payment options."
                                 + (exPaymentFailed.IsSandbox ? "\nError in Sandbox." : "\nError in Live Site.");

                AddUserMessage("PayPal Error", message, UserMessageType.Danger);

                if (CurrentUserProfileOrNull != null && CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                {
                    string adminMessage = exPaymentFailed.ToString()
                                          + "\n\nHTTP Response:\n" + exPaymentFailed.ResponseString
                                          + "\n\nHTTP Headers:\n" + exPaymentFailed.ResponseHeaders;
                    AddUserMessage("PayPal Error (admin info)", "Error " + adminMessage, UserMessageType.Danger);
                }

                return(RedirectToAction("PaymentInfo"));
            }
            catch (Exception ex)
            {
                string message = "Sorry, there was an error starting starting your order with PayPal. Please contact us for other payment options.";
                AddUserMessage("PayPal Error", message, UserMessageType.Danger);

                if (CurrentUserProfileOrNull != null && CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                {
                    string adminMessage = "Exception: " + ex.ToString();
                    AddUserMessage("PayPal Error (admin info)", "Error " + adminMessage, UserMessageType.Danger);
                }
                return(RedirectToAction("PaymentInfo"));
            }

            CartPaymentInfo cartPaymentInfo = cart.CartPaymentInfo;

            if (cartPaymentInfo == null)
            {
                cartPaymentInfo = GStoreDb.CartPaymentInfos.Create();
                cartPaymentInfo.SetFromPayPalResponse(cart, response);
                if (webFormResponse != null)
                {
                    cartPaymentInfo.WebFormResponseId = webFormResponse.WebFormResponseId;
                }
                cartPaymentInfo = GStoreDb.CartPaymentInfos.Add(cartPaymentInfo);
            }
            else
            {
                cartPaymentInfo.SetFromPayPalResponse(cart, response);
                if (webFormResponse != null)
                {
                    cartPaymentInfo.WebFormResponseId = webFormResponse.WebFormResponseId;
                }
                cartPaymentInfo = GStoreDb.CartPaymentInfos.Update(cartPaymentInfo);
            }

            GStoreDb.SaveChanges();

            cart.CartPaymentInfoId          = cartPaymentInfo.CartPaymentInfoId;
            cart.StatusPaymentInfoConfirmed = false;
            cart = GStoreDb.Carts.Update(cart);
            GStoreDb.SaveChanges();

            PayPalLinkData confirmLink = response.links.Where(l => l.rel == "approval_url").SingleOrDefault();

            if (string.IsNullOrEmpty(confirmLink.href))
            {
                string message = "Sorry, there was an error getting your order info from PayPal. Please contact us for other payment options.";
                AddUserMessage("PayPal Error", message, UserMessageType.Danger);
                if (CurrentUserProfileOrNull != null && CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                {
                    string adminMessage = "PayPal Response parse error. Cannot find link with method: approval_url";
                    AddUserMessage("PayPal Error (admin info)", "Error " + adminMessage, UserMessageType.Danger);
                }
                return(RedirectToAction("PaymentInfo"));
            }

            return(Redirect(confirmLink.href));
        }
Example #6
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 #7
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 #8
0
 public CheckoutWebFormInfo(CheckoutViewModelBase checkoutViewModel, WebForm webForm, WebFormResponse webFormResponse)
 {
     this.CheckoutViewModel = checkoutViewModel;
     this.WebForm           = webForm;
     this.WebFormResponse   = webFormResponse;
 }
Example #9
0
        private static void FillWebFormResponses(BaseController controller, WebFormResponse webFormResponse, WebForm webForm, WebFormResponse oldResponseOrNull)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            IGstoreDb               db                      = controller.GStoreDb;
            UserProfile             userProfile             = controller.CurrentUserProfileOrNull;
            StoreFrontConfiguration storeFrontConfiguration = controller.CurrentStoreFrontConfigOrThrow;

            if (webFormResponse == null)
            {
                throw new ArgumentNullException("webFormResponse");
            }
            if (webForm == null)
            {
                throw new ArgumentNullException("webFormResponse");
            }

            List <WebFormField> fields = webForm.WebFormFields.AsQueryable().WhereIsActive().ApplySortDefault().ToList();

            foreach (WebFormField field in fields)
            {
                WebFormFieldResponse oldFieldResponse = null;
                WebFormFieldResponse fieldResponse    = null;
                if (oldResponseOrNull != null)
                {
                    oldFieldResponse = oldResponseOrNull.WebFormFieldResponses.SingleOrDefault(wffr => wffr.WebFormFieldId == field.WebFormFieldId);
                }
                if (oldFieldResponse != null)
                {
                    fieldResponse = oldFieldResponse;
                }
                else
                {
                    fieldResponse = db.WebFormFieldResponses.Create();
                    fieldResponse.WebFormField   = field;
                    fieldResponse.WebFormFieldId = field.WebFormFieldId;
                    fieldResponse.SetDefaults(userProfile);
                }

                fieldResponse.ClientId              = storeFrontConfiguration.ClientId;
                fieldResponse.Client                = storeFrontConfiguration.Client;
                fieldResponse.StoreFrontId          = storeFrontConfiguration.StoreFrontId;
                fieldResponse.StoreFront            = storeFrontConfiguration.StoreFront;
                fieldResponse.DataType              = field.DataType;
                fieldResponse.DataTypeString        = field.DataTypeString;
                fieldResponse.IsPending             = false;
                fieldResponse.StartDateTimeUtc      = DateTime.UtcNow.AddMinutes(-1);
                fieldResponse.EndDateTimeUtc        = DateTime.UtcNow.AddYears(100);
                fieldResponse.WebFormFieldLabelText = field.LabelText;
                fieldResponse.WebFormFieldName      = field.Name;
                fieldResponse.WebFormFieldOrder     = field.Order;
                fieldResponse.WebFormName           = field.WebForm.Name;
                fieldResponse.WebFormOrder          = field.WebForm.Order;

                fieldResponse.SetValueFieldsFromFormValues(controller.Request);

                if (oldFieldResponse == null)
                {
                    db.WebFormFieldResponses.Add(fieldResponse);
                }
                else
                {
                    db.WebFormFieldResponses.Update(fieldResponse);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Processes a web form and saves result to file, database, or email based on web form settings.
        /// Also handles newly registered user form
        /// </summary>
        public static bool ProcessWebForm(this BaseController controller, WebForm webForm, Page page, bool isRegisterPage, WebFormResponse oldResponseToUpdateOrNull)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            if (webForm == null)
            {
                throw new ArgumentNullException("webForm");
            }
            if (page == null && (!isRegisterPage))
            {
                throw new ArgumentNullException("page");
            }
            if (!isRegisterPage && !(page.WebFormSaveToDatabase || page.WebFormSaveToFile || page.WebFormSendToEmail))
            {
                throw new ArgumentException("No form processing specified in Page. One of the following must be enabled: page.WebFormSaveToDatabase or page.WebFormSaveToFile or page.WebFormSendToEmail", "page");
            }

            bool isValid = ValidateFields(controller, webForm);

            if (!controller.ModelState.IsValid || !isValid)
            {
                return(false);
            }

            string formBodyText = BuildFormBodyText(controller, webForm, page, false);
            string formSubject  = BuildFormSubject(controller, webForm, page);

            if (page == null || page.WebFormSaveToDatabase)
            {
                //register forms always go to database
                ProcessWebForm_ToDatabase(controller, webForm, page, formSubject, formBodyText, isRegisterPage, oldResponseToUpdateOrNull);
            }

            if (!isRegisterPage)
            {
                bool savedToFile = false;
                bool emailed     = false;
                if (page.WebFormSaveToFile)
                {
                    savedToFile = ProcessWebForm_ToFile(controller, webForm, page);
                }
                if (page.WebFormSendToEmail)
                {
                    emailed = ProcessWebForm_ToEmail(controller, webForm, page);
                }
            }

            return(true);
        }