コード例 #1
0
        public HttpResponseMessage CancelEntry()
        {
            int id;

            if (int.TryParse(HttpContext.Current.Request.Form["_id"], out id) == false)
            {
                return(ValidationErrorResponse("Could not find _id in the request data"));
            }
            var rowId = Guid.Empty;

            Guid.TryParse(HttpContext.Current.Request.Form["_rowId"], out rowId);
            var content = Umbraco.TypedContent(id);

            if (content == null)
            {
                return(ValidationErrorResponse("Could not any content with id {0}", id));
            }
            var property = content.ContentType.PropertyTypes.FirstOrDefault(p => p.PropertyEditorAlias == FormModel.PropertyEditorAlias);

            if (property == null)
            {
                return(ValidationErrorResponse("Could not find any form property on content with id {0}", id));
            }
            FormModel formModel = null;

            try
            {
                formModel = content.GetPropertyValue <FormModel>(property.PropertyTypeAlias);
            }
            catch (Exception ex)
            {
                return(ValidationErrorResponse("Could not extract the form property on content with id {0}: {1}", id, ex.Message));
            }
            if (rowId != Guid.Empty)
            {
                formModel.LoadValues(content, rowId);
            }
            var successData = new SubmissionSuccessData(formModel.RowId);

            if (formModel.SuccessPageId <= 0)
            {
                return(SubmissionSuccessResponse(successData));
            }

            var successPage = Umbraco.TypedContent(formModel.SuccessPageId);

            if (successPage == null || !Umbraco.MemberHasAccess(successPage.Path))
            {
                return(SubmissionSuccessResponse(successData));
            }

            successData.RedirectUrl           = Umbraco.NiceUrl(formModel.SuccessPageId);
            successData.RedirectUrlWithDomain = Umbraco.NiceUrlWithDomain(formModel.SuccessPageId);
            return(SubmissionSuccessResponse(successData));
        }
コード例 #2
0
        public HttpResponseMessage SubmitEntry()
        {
            int id;

            if (int.TryParse(HttpContext.Current.Request.Form["_id"], out id) == false)
            {
                return(ValidationErrorResponse("Could not find _id in the request data"));
            }

            var content = Umbraco.TypedContent(id);

            if (content == null)
            {
                return(ValidationErrorResponse("Could not any content with id {0}", id));
            }

            // set the correct culture for this request
            var domain = Services.DomainService.GetAssignedDomains(content.AncestorOrSelf(1).Id, true).FirstOrDefault();

            if (domain != null && string.IsNullOrEmpty(domain.LanguageIsoCode) == false)
            {
                var culture = new CultureInfo(domain.LanguageIsoCode);
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }

            if (Umbraco.MemberHasAccess(content.Path) == false)
            {
                return(Request.CreateUserNoAccessResponse());
            }

            var property = content.ContentType.PropertyTypes.FirstOrDefault(p => p.PropertyEditorAlias == FormModel.PropertyEditorAlias);

            if (property == null)
            {
                return(ValidationErrorResponse("Could not find any form property on content with id {0}", id));
            }

            FormModel formModel = null;

            try
            {
                formModel = content.GetPropertyValue <FormModel>(property.PropertyTypeAlias);
            }
            catch (Exception ex)
            {
                return(ValidationErrorResponse("Could not extract the form property on content with id {0}: {1}", id, ex.Message));
            }

            var result = formModel.CollectSubmittedValues(content, false);

            if (result == false)
            {
                var errorData = new ValidationErrorData
                {
                    InvalidFields     = formModel.AllValueFields().Where(f => f.Invalid).ForClientSide(),
                    FailedValidations = formModel.Validations.Where(v => v.Invalid).ForClientSide()
                };
                return(ValidationErrorResponse(errorData));
            }

            var successData = new SubmissionSuccessData();

            if (formModel.SuccessPageId <= 0)
            {
                return(SubmissionSuccessResponse(successData));
            }

            var successPage = Umbraco.TypedContent(formModel.SuccessPageId);

            if (successPage == null || !Umbraco.MemberHasAccess(successPage.Path))
            {
                return(SubmissionSuccessResponse(successData));
            }

            successData.RedirectUrl           = Umbraco.NiceUrl(formModel.SuccessPageId);
            successData.RedirectUrlWithDomain = Umbraco.NiceUrlWithDomain(formModel.SuccessPageId);
            return(SubmissionSuccessResponse(successData));
        }
コード例 #3
0
 private HttpResponseMessage SubmissionSuccessResponse(SubmissionSuccessData successData)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, successData, GetFormatter()));
 }
コード例 #4
0
ファイル: PublicController.cs プロジェクト: alecrt/FormEditor
        public HttpResponseMessage SubmitEntry()
        {
            int id;
            if (int.TryParse(HttpContext.Current.Request.Form["_id"], out id) == false)
            {
                return ValidationErrorResponse("Could not find _id in the request data");
            }
            var rowId = Guid.Empty;
            Guid.TryParse(HttpContext.Current.Request.Form["_rowId"], out rowId);

            var content = Umbraco.TypedContent(id);
            if (content == null)
            {
                return ValidationErrorResponse("Could not any content with id {0}", id);
            }

            // set the correct culture for this request
            var domain = Services.DomainService.GetAssignedDomains(content.AncestorOrSelf(1).Id, true).FirstOrDefault();
            if(domain != null && string.IsNullOrEmpty(domain.LanguageIsoCode) == false)
            {
                var culture = new CultureInfo(domain.LanguageIsoCode);
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }

            if (Umbraco.MemberHasAccess(content.Path) == false)
            {
                return Request.CreateUserNoAccessResponse();
            }

            var property = content.ContentType.PropertyTypes.FirstOrDefault(p => p.PropertyEditorAlias == FormModel.PropertyEditorAlias);
            if (property == null)
            {
                return ValidationErrorResponse("Could not find any form property on content with id {0}", id);
            }

            FormModel formModel = null;
            try
            {
                formModel = content.GetPropertyValue<FormModel>(property.PropertyTypeAlias);
            }
            catch (Exception ex)
            {
                return ValidationErrorResponse("Could not extract the form property on content with id {0}: {1}", id, ex.Message);
            }
            if(rowId != Guid.Empty)
            {
                formModel.LoadValues(content, rowId);
            }
            var result = formModel.CollectSubmittedValues(content, false);
            if (result == false)
            {
                var errorData = new ValidationErrorData
                {
                    InvalidFields = formModel.AllValueFields().Where(f => f.Invalid).ForFrontEnd(),
                    FailedValidations = formModel.Validations.Where(v => v.Invalid).ForFrontEnd()
                };
                return ValidationErrorResponse(errorData);
            }

            var successData = new SubmissionSuccessData(formModel.RowId);
            if (formModel.SuccessPageId <= 0)
            {
                return SubmissionSuccessResponse(successData);
            }

            var successPage = Umbraco.TypedContent(formModel.SuccessPageId);
            if (successPage == null || !Umbraco.MemberHasAccess(successPage.Path))
            {
                return SubmissionSuccessResponse(successData);
            }

            successData.RedirectUrl = Umbraco.NiceUrl(formModel.SuccessPageId);
            successData.RedirectUrlWithDomain = Umbraco.NiceUrlWithDomain(formModel.SuccessPageId);
            return SubmissionSuccessResponse(successData);
        }
コード例 #5
0
ファイル: PublicController.cs プロジェクト: alecrt/FormEditor
 private HttpResponseMessage SubmissionSuccessResponse(SubmissionSuccessData successData)
 {
     return Request.CreateResponse(HttpStatusCode.OK, successData, GetFormatter());
 }