コード例 #1
0
ファイル: PluginHelper.cs プロジェクト: nguyenhuy2911/CMS
        public static ActionResult ReturnActionResult(ControllerContext controllerContext, object model, Exception exception)
        {
            var    jsonResult  = controllerContext.RequestContext.GetRequestValue("JsonResult");
            string redirectUrl = "";

            if (exception == null)
            {
                redirectUrl = controllerContext.RequestContext.GetRequestValue("SuccessedUrl");
            }
            else
            {
                controllerContext.HttpContext.Session["Exception"] = exception;
                redirectUrl = controllerContext.RequestContext.GetRequestValue("FailedUrl");
            }
            if (jsonResult.EqualsOrNullEmpty("true", StringComparison.OrdinalIgnoreCase))
            {
                var data = new JsonResultData()
                {
                    Model = model, RedirectUrl = redirectUrl
                };
                if (exception != null)
                {
                    data.AddException(exception);
                    if ((exception is RuleViolationException))
                    {
                        ((RuleViolationException)exception).FillIssues(controllerContext.Controller.ViewData.ModelState);
                        data.AddModelState(controllerContext.Controller.ViewData.ModelState);
                    }
                }
                return(new JsonResult()
                {
                    Data = data
                });
            }
            if (exception != null && string.IsNullOrEmpty(redirectUrl))
            {
                throw exception;
            }

            if (!string.IsNullOrEmpty(redirectUrl))
            {
                return(new RedirectResult(redirectUrl));
            }

            if (controllerContext.HttpContext.Request.UrlReferrer != null)
            {
                return(new RedirectResult(controllerContext.HttpContext.Request.UrlReferrer.OriginalString));
            }
            return(new EmptyResult());
        }
コード例 #2
0
ファイル: TextContentController.cs プロジェクト: FordSoft/CMS
        public virtual ActionResult Edit(string folderName, string uuid, FormCollection form, string @return, bool localize = false)
        {
            var data = new JsonResultData();

            try
            {
                if (ModelState.IsValid)
                {
                    TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();
                    var        schema     = textFolder.GetSchema().AsActual();

                    SchemaPath schemaPath = new SchemaPath(schema);
                    IEnumerable <TextContent> addedCategories;
                    IEnumerable <TextContent> removedCategories;

                    ParseCategories(form, out addedCategories, out removedCategories);
                    ContentBase content;
                    TextContent previous = Session["EditableObject"] as TextContent;

                    TextContentManager.Update(Repository, textFolder, uuid, form,
                                              Request.Files, DateTime.UtcNow, addedCategories, removedCategories, User.Identity.Name,
                                              previous: previous);

                    if (localize == true)
                    {
                        TextContentManager.Localize(textFolder, uuid);
                    }

                    data.RedirectToOpener = true;

                    data.RedirectUrl = @return;
                }
            }
            catch (RuleViolationException violationException)
            {
                foreach (var item in violationException.Issues)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
                data.Success = false;
            }
            catch (Exception e)
            {
                data.AddException(e);
            }
            data.AddModelState(ModelState);
            return(Json(data));
        }
コード例 #3
0
        public System.Web.Mvc.ActionResult Submit(Models.Site site, System.Web.Mvc.ControllerContext controllerContext, Models.SubmissionSetting submissionSetting)
        {
            JsonResultData resultData = new JsonResultData();

            if (!ChangePasswordCore(controllerContext, submissionSetting))
            {
                resultData.AddModelState(controllerContext.Controller.ViewData.ModelState);
                resultData.Success = false;
            }
            else
            {
                resultData.RedirectUrl = MemberPluginHelper.GetReturnUrl(controllerContext);
                resultData.Success     = true;
            }
            return(new JsonResult()
            {
                Data = resultData
            });
        }
コード例 #4
0
        public System.Web.Mvc.ActionResult Submit(Models.Site site, System.Web.Mvc.ControllerContext controllerContext, Models.SubmissionSetting submissionSetting)
        {
            JsonResultData resultData = new JsonResultData();
            string         redirectUrl;

            if (!ContactSiteCore(controllerContext, submissionSetting, out redirectUrl))
            {
                resultData.AddModelState(controllerContext.Controller.ViewData.ModelState);
                resultData.Success = false;
            }
            else
            {
                resultData.RedirectUrl = redirectUrl;
                resultData.Success     = true;
            }
            return(new JsonResult()
            {
                Data = resultData
            });
        }
コード例 #5
0
        public System.Web.Mvc.ActionResult Submit(Models.Site site, System.Web.Mvc.ControllerContext controllerContext, Models.SubmissionSetting submissionSetting)
        {
            JsonResultData      resultData = new JsonResultData();
            ValidateMemberModel model;

            if (!LoginCore(controllerContext, submissionSetting, out model))
            {
                resultData.AddModelState(controllerContext.Controller.ViewData.ModelState);
                resultData.Success = false;
            }
            else
            {
                resultData.RedirectUrl = model.RedirectUrl;
                resultData.Model       = model.UserName;
                resultData.Success     = true;
            }
            return(new JsonResult()
            {
                Data = resultData
            });
        }
コード例 #6
0
        public virtual ActionResult Create(CreateMembershipUserModel model, string @return)
        {
            JsonResultData data = new JsonResultData();

            if (ModelState.IsValid)
            {
                data.RunWithTry((resultData) =>
                {
                    try
                    {
                        _manager.Create(Membership, model.UserName, model.Email, model.Password, model.IsApproved, model.Culture, model.TimeZoneId, model.PasswordQuestion, model.PasswordAnswer
                                        , model.MembershipGroups, model.Profiles, model.Comment);
                        resultData.RedirectUrl = @return;
                    }
                    catch (DataViolationException dataViolationException)
                    {
                        ModelState.FillDataViolation(dataViolationException.Violations);
                    }
                });
            }
            data.AddModelState(ModelState);
            return(Json(data));
        }
コード例 #7
0
ファイル: TextContentController.cs プロジェクト: webrot/CMS
        public virtual ActionResult Create(string folderName, string parentFolder, string parentUUID, FormCollection form, string @return)
        {
            var data = new JsonResultData();

            try
            {
                if (ModelState.IsValid)
                {
                    TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();
                    var        schema     = textFolder.GetSchema().AsActual();

                    SchemaPath schemaPath = new SchemaPath(schema);
                    IEnumerable <TextContent> addedCategories;
                    IEnumerable <TextContent> removedCategories;

                    ParseCategories(form, out addedCategories, out removedCategories);
                    ContentBase content;

                    content = TextContentManager.Add(Repository, textFolder, parentFolder, parentUUID, form, Request.Files, addedCategories, User.Identity.Name);

                    data.RedirectUrl = @return;
                }
            }
            catch (RuleViolationException ruleEx)
            {
                foreach (var item in ruleEx.Issues)
                {
                    data.AddFieldError(item.PropertyName, item.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                data.AddException(e);
            }
            data.AddModelState(ModelState);
            return(Json(data));
        }
コード例 #8
0
        public System.Web.Mvc.ActionResult Submit(Site site, ControllerContext controllerContext, SubmissionSetting submissionSetting)
        {
            // Setup temp fields
            Site = site;
            ControllerContext = controllerContext;
            SubmissionSetting = submissionSetting;

            var model = new TModel();

            if (!ModelBindHelper.BindModel <TModel>(model, "", ControllerContext, SubmissionSetting))
            {
                var resultData = new JsonResultData();
                resultData.Success = false;
                resultData.AddModelState(ControllerContext.Controller.ViewData.ModelState);

                ClearTempFields();

                return(new JsonResult {
                    Data = resultData
                });
            }

            try
            {
                var result = Execute(model);

                string redirectUrl = null;

                if (result != null)
                {
                    redirectUrl = result.RedirectUrl;
                }

                if (!String.IsNullOrEmpty(redirectUrl))
                {
                    return(RedirectTo(redirectUrl, result == null ? null : result.Data));
                }
                else
                {
                    return(new JsonResult
                    {
                        Data = new JsonResultData
                        {
                            Success = true,
                            Model = result == null ? null : result.Data
                        }
                    });
                }
            }
            catch (InvalidModelStateException ex)
            {
                var resultData = new JsonResultData();
                resultData.Success = false;
                resultData.AddModelState(ex.ModelState);

                return(new JsonResult {
                    Data = resultData
                });
            }
            catch (Exception ex)
            {
                Kooboo.HealthMonitoring.Log.LogException(ex);

                var resultData = new JsonResultData();
                resultData.Success = false;
                resultData.AddException(ex);

                return(new JsonResult {
                    Data = resultData
                });
            }
            finally
            {
                ClearTempFields();
            }
        }