Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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));
        }
        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
            });
        }
Esempio n. 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
            });
        }
Esempio n. 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
            });
        }
Esempio n. 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));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 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();
            }
        }