示例#1
0
 public bool MaxSubmissionsExceededForCurrentUser(IPublishedContent content)
 {
     return(MaxSubmissionsForCurrentUserHandler.CanSubmit(this, content) == false);
 }
示例#2
0
        public bool CollectSubmittedValues(IPublishedContent content, bool redirect = true)
        {
            if (content == null)
            {
                return(false);
            }

            // currently not supporting GET forms ... will require some limitation on fields and stuff
            if (Request.HttpMethod != "POST")
            {
                return(false);
            }

            // does the form contain an "_id" and if so, does it match the supplied content?
            int id;

            if (int.TryParse(HttpContext.Current.Request.Form["_id"], out id) && id != content.Id)
            {
                return(false);
            }

            // are we able to accept any submissions for this form for the current user?
            if (MaxSubmissionsExceededForCurrentUser(content))
            {
                return(false);
            }

            // are we able to accept any submissions for this form at all?
            if (MaxSubmissionsExceeded(content))
            {
                return(false);
            }

            // first collect the submitted values
            var fields = CollectSubmittedValuesFromRequest(content);

            // next validate the submitted values
            if (ValidateSubmittedValues(content, fields) == false)
            {
                return(false);
            }

            // load the data type prevalues for various settings (log IP, email templates etc)
            LoadPreValues(content);

            // get all "fields with value"
            var valueFields = AllValueFields().ToList();

            // next execute all validations (if validation is enabled)
            if (IsVisibleTab(TabOrder.Ids.Validation) && ExecuteValidations(content, valueFields) == false)
            {
                return(false);
            }

            // we're about to add data to the index - let's run the before add to index event handler
            var beforeAddToIndexErrorMessage = RaiseBeforeAddToIndex(content);

            if (beforeAddToIndexErrorMessage != null)
            {
                // the event was cancelled - use the validation system to pass the error message back to the user
                Validations = new List <Validation.Validation>(Validations ?? new Validation.Validation[] { })
                {
                    new Validation.Validation
                    {
                        ErrorMessage = beforeAddToIndexErrorMessage,
                        Invalid      = true,
                        Rules        = new Validation.Rule[] {}
                    }
                };
                return(false);
            }

            // before add to index event handling did not cancel - add to index
            RowId = AddSubmittedValuesToIndex(content, valueFields);
            if (RowId == Guid.Empty)
            {
                return(false);
            }

            SubmitToWebService(content);

            // tell everyone that something was added
            RaiseAfterAddToIndex(content, fields);

            MaxSubmissionsForCurrentUserHandler.HandleSubmission(this, content);

            SendEmails(content, valueFields);

            if (redirect && SuccessPageId > 0)
            {
                RedirectToSuccesPage();
            }

            return(true);
        }