Esempio n. 1
0
        public virtual ActionResult CrossPageSort(ContentSorter sourceContent, string folderName, int?page, int?pageSize, bool up = true)
        {
            var entry = new JsonResultEntry();

            try
            {
                //page = page ?? 1;
                //pageSize = pageSize ?? 50;
                var textFolder = new TextFolder(Repository, folderName);
                var content    = new TextFolder(Repository, folderName).CreateQuery().WhereEquals("UUID", sourceContent.UUID).FirstOrDefault();

                TextContent destContent;
                if (up)
                {
                    destContent = content.Previous();
                }
                else
                {
                    destContent = content.Next();
                }
                if (destContent != null)
                {
                    ServiceFactory.TextContentManager.Update(textFolder, sourceContent.UUID, "Sequence", destContent["Sequence"], User.Identity.Name);
                    ServiceFactory.TextContentManager.Update(textFolder, destContent.UUID, "Sequence", content["Sequence"], User.Identity.Name);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return(Json(entry));
        }
Esempio n. 2
0
        public virtual ActionResult Delete(Element[] model, ElementCategory[] categoryList)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                var category = ControllerContext.RequestContext.GetRequestValue("Category");

                if (model != null)
                {
                    foreach (var m in model)
                    {
                        m.Category = category;
                        Remove(m);
                    }
                }


                if (categoryList != null)
                {
                    foreach (var c in categoryList)
                    {
                        Manager.RemoveCategory(Site, c.Category);
                    }
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Esempio n. 3
0
        public virtual ActionResult Draft(Page newModel, string old_key, bool?preview, bool?published)
        {
            JsonResultEntry result = new JsonResultEntry();

            try
            {
                newModel.Site = Site;

                var old = Manager.Get(Site, old_key);

                SavePosition(newModel);

                newModel.Published = false;
                newModel.UserName  = User.Identity.Name;
                Manager.PageProvider.SaveAsDraft(newModel);

                if (published.HasValue && published.Value == true)
                {
                    Manager.Publish(old, true, User.Identity.Name);

                    result.RedirectUrl = GetReturnUrl();
                }
                result.AddMessage("The item has been saved.".Localize());
            }
            catch (Exception e)
            {
                result.AddException(e);
            }

            return(Json(result));
        }
Esempio n. 4
0
        public virtual ActionResult ReconfigContent(IEnumerable <ContentSorter> list, string folderName, string uuid, string parentUUID)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();
                if (!string.IsNullOrEmpty(uuid) && string.Compare(uuid, parentUUID, true) != 0)
                {
                    ServiceFactory.TextContentManager.Update(textFolder, uuid, new[] { "ParentUUID", "ParentFolder" },
                                                             new[] { parentUUID, folderName }, User.Identity.Name);
                }

                var schema = textFolder.GetSchema().AsActual();
                foreach (var c in list)
                {
                    ServiceFactory.TextContentManager.Update(Repository, schema, c.UUID, new string[] { "Sequence" }, new object[] { c.Sequence }, User.Identity.Name);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Esempio n. 5
0
        public virtual ActionResult DeleteRepository(string siteName, bool deleteRepository)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);

            try
            {
                if (!string.IsNullOrEmpty(siteName))
                {
                    var site = SiteHelper.Parse(siteName).AsActual();
                    if (site != null && !string.IsNullOrEmpty(site.Repository))
                    {
                        var sharedDb = ServiceFactory.SiteManager.UseSharedDB(site);
                        if (!sharedDb || (sharedDb && deleteRepository))
                        {
                            var repository = site.GetRepository();
                            Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Remove(repository);


                            site.Repository = null;
                            ServiceFactory.SiteManager.Update(site);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }
            return(Json(resultEntry));
        }
Esempio n. 6
0
        public virtual ActionResult Create(Schema schema, bool?finish)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);

            try
            {
                if (ModelState.IsValid)
                {
                    Manager.Add(Repository, schema);

                    this.ResetAllForm(schema.Name);

                    if (finish.Value == true)
                    {
                        resultEntry.RedirectUrl = this.Url.Action("Index", Request.RequestContext.AllRouteValues().Merge("schemaName", schema.Name));
                    }
                    else
                    {
                        resultEntry.RedirectUrl = this.Url.Action("Templates", Request.RequestContext.AllRouteValues().Merge("schemaName", schema.Name));
                    }
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }
            return(Json(resultEntry));
        }
Esempio n. 7
0
        public virtual ActionResult BatchUnpublish(string folderName, string parentFolder, string[] docArr)
        {
            JsonResultEntry entry = new JsonResultEntry();

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

                if (docArr != null)
                {
                    foreach (var doc in docArr)
                    {
                        if (string.IsNullOrEmpty(doc))
                        {
                            continue;
                        }

                        ServiceFactory.TextContentManager.Update(Repository, schema, doc, new string[] { "Published" },
                                                                 new object[] { false }, User.Identity.Name);
                    }
                }

                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return(Json(entry));
        }
Esempio n. 8
0
        public virtual ActionResult Edit(string folderName)
        {
            JsonResultEntry entry = new JsonResultEntry();

            if (ModelState.IsValid)
            {
                try
                {
                    var old  = FolderManager.Get(Repository, folderName);
                    var @new = FolderManager.Get(Repository, folderName);
                    TryUpdateModel(@new);

                    FolderManager.Update(Repository, @new, old);

                    entry.Model = new
                    {
                        folderName = @new.FullName
                    };
                }
                catch (Exception e)
                {
                    entry.AddException(e);
                }
            }
            else
            {
                entry.AddModelState(ModelState);
            }

            return(Json(entry));
        }
Esempio n. 9
0
        public virtual ActionResult Edit(Schema newModel, string old_key, bool?finish, bool Next, bool resetAll)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);

            try
            {
                if (ModelState.IsValid)
                {
                    var oldModel = Manager.Get(Repository, old_key);
                    Manager.Update(Repository, newModel, oldModel);

                    if (resetAll)
                    {
                        ResetAllForm(newModel.Name);
                    }
                    if (finish.Value == true)
                    {
                        resultEntry.RedirectUrl = this.Url.Action("Index", Request.RequestContext.AllRouteValues().Merge("schemaName", newModel.Name));
                    }
                    else
                    {
                        resultEntry.RedirectUrl = this.Url.Action("Templates", Request.RequestContext.AllRouteValues().Merge("schemaName", newModel.Name));
                    }
                    //}
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }
            return(Json(resultEntry));
        }
Esempio n. 10
0
        public virtual ActionResult Publish(string folderName, string parentFolder, string uuid)
        {
            var entry = new JsonResultEntry();

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

                TextContent textContent = schema.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault();
                var         published   = (bool?)textContent["Published"];
                if (published.HasValue && published.Value == true)
                {
                    ServiceFactory.TextContentManager.Update(Repository, schema, uuid, new string[] { "Published" }, new object[] { false }, User.Identity.Name);
                }
                else
                {
                    ServiceFactory.TextContentManager.Update(Repository, schema, uuid, new string[] { "Published" }, new object[] { true }, User.Identity.Name);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Esempio n. 11
0
        public override ActionResult Edit(CMS.Sites.Models.View newModel, string old_key)
        {
            JsonResultEntry entry = new JsonResultEntry();
            try
            {
                if (ModelState.IsValid)
                {
                    newModel.UserName = User.Identity.Name;
                    Update(newModel, old_key);
                    var pageRedirect = Request.Form["pageRedirect"];
                    entry.AddMessage("The item has been saved.".Localize()).SetSuccess().RedirectUrl = string.Equals(pageRedirect, "true", StringComparison.OrdinalIgnoreCase) ? this.Url.Action("Index", this.ControllerContext.RequestContext.AllRouteValues()) : null;

                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return Json(entry);
        }
Esempio n. 12
0
        public virtual ActionResult Ajax(LoginModel loginModel, int redirect)
        {
            var resultData = new JsonResultEntry();

            try
            {
                if (UserServices.ValidateUser(loginModel.UserName, loginModel.Password) != null)
                {
                    System.Web.Security.FormsAuthentication.SetAuthCookie(loginModel.UserName, loginModel.RememberMe);
                    if (redirect == 0)
                    {
                        resultData.RedirectUrl = Request.UrlReferrer.ToString();
                    }
                    else
                    {
                        resultData.RedirectUrl = System.Web.Security.FormsAuthentication.DefaultUrl;
                    }
                }
                else
                {
                    ModelState.AddModelError("UserName", "Username and/or password are incorrect.".Localize());
                }

                resultData.AddModelState(ModelState);
            }
            catch (Exception e)
            {
                resultData.AddException(e);
            }
            return(Json(resultData));
        }
Esempio n. 13
0
        public virtual ActionResult ResetAll(string schemaName, FormType CurrentFormType)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);

            try
            {
                Schema schema = new Schema(Repository, schemaName);

                var formTypes = Enum.GetValues(typeof(FormType));

                List <object> formList = new List <object>();

                foreach (var t in formTypes)
                {
                    formList.Add(new
                    {
                        Body     = schema.GenerateForm((FormType)t),
                        FormType = t.ToString()
                    });
                }

                resultEntry.Model = formList;
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }
            return(Json(resultEntry));
        }
Esempio n. 14
0
        public virtual ActionResult Create([Bind(Exclude = "Parent")] Site site, string parent, string template)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ViewData.ModelState);

            try
            {
                if (ModelState.IsValid)
                {
                    Site parentSite = null;
                    if (!string.IsNullOrEmpty(parent))
                    {
                        parentSite = new Site(SiteHelper.SplitFullName(parent));
                    }
                    var createdSite = Kooboo.CMS.Sites.Services.ServiceFactory.SiteManager.Create(parentSite, site.Name, template, site, User.Identity.Name);

                    resultEntry.RedirectUrl = Url.Action("SiteMap", new { controller = "home", siteName = createdSite.FullName });
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return(Json(resultEntry));
        }
Esempio n. 15
0
        public virtual ActionResult TempFile()
        {
            var entry = new JsonResultEntry();

            try
            {
                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    var postFile       = Request.Files[0];
                    var repositoryPath = new RepositoryPath(Repository);
                    var tempPath       = Kooboo.Web.Url.UrlUtility.Combine(repositoryPath.VirtualPath, "Temp");
                    Kooboo.IO.IOUtility.EnsureDirectoryExists(Server.MapPath(tempPath));

                    var fileUrl = Kooboo.Web.Url.UrlUtility.Combine(tempPath, UniqueIdGenerator.GetInstance().GetBase32UniqueId(24) + Path.GetExtension(postFile.FileName));

                    postFile.SaveAs(Server.MapPath(fileUrl));
                    entry.Model = Url.Content(fileUrl);
                }
                else
                {
                    entry.SetFailed().AddMessage("It is not a valid image file.".Localize());
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Esempio n. 16
0
        public virtual ActionResult Create(MediaFolder model, string folderName)
        {
            var entry = new JsonResultEntry();

            if (ModelState.IsValid)
            {
                try
                {
                    MediaFolder parent = null;
                    if (!string.IsNullOrEmpty(folderName))
                    {
                        parent = FolderHelper.Parse <MediaFolder>(Repository, folderName).AsActual();
                    }
                    model.Parent = parent;

                    FolderManager.Add(Repository, model);
                }
                catch (Exception e)
                {
                    entry.AddException(e);
                }
            }
            else
            {
                entry.AddModelState(ModelState);
            }

            return(Json(entry));
        }
Esempio n. 17
0
        public virtual ActionResult Copy(string folderName, string parentFolder, string[] docArr, string[] folderArr)
        {
            JsonResultEntry entry = new JsonResultEntry();

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

                if (docArr != null)
                {
                    foreach (var doc in docArr)
                    {
                        if (string.IsNullOrEmpty(doc))
                        {
                            continue;
                        }

                        ServiceFactory.TextContentManager.Copy(textFolder.GetSchema(), doc);
                    }
                }
                entry.ReloadPage = true;
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return(Json(entry));
        }
Esempio n. 18
0
        public virtual ActionResult CopyContent(string schema, string uuid)
        {
            var result = new JsonResultEntry();

            try
            {
                var content = Kooboo.CMS.Content.Services.ServiceFactory.TextContentManager.Copy(new Schema(Repository.Current, schema), uuid);
                result.Model = new
                {
                    uuid      = content.UUID,
                    schema    = content.SchemaName,
                    published = string.Empty,
                    editUrl   = Url.Action("Edit", new
                    {
                        controller     = "TextContent",
                        Area           = "Contents",
                        RepositoryName = content.Repository,
                        SiteName       = Site.FullName,
                        FolderName     = content.FolderName,
                        UUID           = content.UUID
                    }),
                    summary = HttpUtility.HtmlAttributeEncode(content.GetSummary())
                };
            }
            catch (Exception e)
            {
                result.AddException(e);
            }

            return(Json(result));
        }
Esempio n. 19
0
        public virtual ActionResult PostFile()
        {
            var entry = new JsonResultEntry();

            try
            {
                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    var postFile = Request.Files[0];
                    var tempPath = Kooboo.Web.Url.UrlUtility.Combine(Site.VirtualPath, "Temp");
                    Kooboo.IO.IOUtility.EnsureDirectoryExists(Server.MapPath(tempPath));

                    var fileUrl = Kooboo.Web.Url.UrlUtility.Combine(tempPath, Guid.NewGuid() + Path.GetFileName(postFile.FileName));

                    postFile.SaveAs(Server.MapPath(fileUrl));
                    entry.Model = Url.Content(fileUrl);
                }
                else
                {
                    entry.SetFailed().AddMessage("It is not a valid image file.".Localize());
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Esempio n. 20
0
        public virtual ActionResult Rebroadcast(string folderName, string parentFolder, string[] docArr, string[] folderArr)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();

                if (docArr != null)
                {
                    foreach (var doc in docArr)
                    {
                        if (string.IsNullOrEmpty(doc))
                        {
                            continue;
                        }

                        var textContent = textFolder.CreateQuery().WhereEquals("UUID", doc).FirstOrDefault();
                        if (textContent != null)
                        {
                            Kooboo.CMS.Content.EventBus.Content.ContentEvent.Fire(ContentAction.Add, textContent);
                        }
                    }
                }

                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return(Json(entry));
        }
Esempio n. 21
0
        public virtual ActionResult Upload(string file)
        {
            var entry = new JsonResultEntry();

            try
            {
                if (ModelState.IsValid)
                {
                    var files = this.HttpContext.Request.Files;

                    if (files.Count == 0 || files[0].ContentLength == 0 || !files[0].FileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new KoobooException("Please upload a dll file.");
                    }

                    AssemblyManager.Upload(this.Site, files[0].FileName, files[0].InputStream);
                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }


            return(Json(entry));
        }
Esempio n. 22
0
        public virtual ActionResult Install(InstallModuleModel installModel)
        {
            JsonResultEntry result = new JsonResultEntry()
            {
                RedirectToOpener = false
            };

            try
            {
                if (ModelState.IsValid)
                {
                    var moduleFile = this.Request.Files["ModuleFile"];
                    if (moduleFile == null || moduleFile.ContentLength == 0)
                    {
                        ModelState.AddModelError("ModuleFile", "ModuleFile is null.");
                    }
                    else
                    {
                        StringBuilder log        = new StringBuilder();
                        var           moduleName = System.IO.Path.GetFileNameWithoutExtension(moduleFile.FileName);

                        var moduleInfo = Manager.Install(moduleName, moduleFile.InputStream, ref log);

                        if (moduleInfo == null && log.Length != 0)
                        {
                            result.Success = false;
                            result.AddMessage(log.ToString());
                        }
                        else
                        {
                            result.RedirectUrl = Url.Action("InstallationCompleted", new { moduleName = moduleInfo.ModuleName });

                            //var moduleInstallUrl = moduleInfo.InstallUrl;
                            //if (string.IsNullOrEmpty(moduleInstallUrl))
                            //{
                            //    result.RedirectUrl = Url.Action("InstallationCompleted", new { moduleName = moduleInfo.ModuleName });
                            //}
                            //else
                            //{
                            //    result.RedirectUrl = Url.Action("InstallScaffold", new { moduleName = moduleInfo.ModuleName, installUrl = moduleInstallUrl });
                            //}
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result.AddException(e);
            }

            result.AddModelState(ModelState);
            return(Json(result));
        }
Esempio n. 23
0
        public override ActionResult Edit(Page newModel, string old_key)
        {
            JsonResultEntry result = new JsonResultEntry();

            try
            {
                newModel.Site     = Site;
                newModel.UserName = User.Identity.Name;

                var old = Manager.Get(Site, old_key);

                SavePosition(newModel);

                var saveAsDraft = this.Request.Form["SaveAsDraft"];

                result.RedirectUrl = GetReturnUrl();

                if (!string.IsNullOrEmpty(saveAsDraft) && saveAsDraft.ToLower() == "true")
                {
                    Manager.PageProvider.SaveAsDraft(newModel);
                    result.Model = new { preview = true };
                    //result.RedirectUrl = Url.Action("Draft", ControllerContext.RequestContext.AllRouteValues());
                }
                else
                {
                    var setPublished = Request.Form["SetPublished"];
                    if (!string.IsNullOrEmpty(setPublished))
                    {
                        var published = false;
                        bool.TryParse(setPublished, out published);
                        newModel.Published = published;
                    }
                    else
                    {
                        result.RedirectUrl = null;
                        result.AddMessage("The item has been saved.".Localize());
                    }
                    Manager.Update(Site, newModel, old);
                }

                if (string.IsNullOrEmpty(result.RedirectUrl))
                {
                    result.Model = FrontUrlHelper.Preview(Url, Kooboo.CMS.Sites.Models.Site.Current, newModel, null).ToString();
                }
            }
            catch (Exception e)
            {
                result.AddException(e);
            }

            return(Json(result));
        }
Esempio n. 24
0
        public virtual ActionResult DeleteContent(string schema, string uuid)
        {
            var result = new JsonResultEntry();

            try
            {
                Kooboo.CMS.Content.Services.ServiceFactory.TextContentManager.Delete(Repository.Current, new Schema(Repository.Current, schema), uuid);
            }
            catch (Exception e)
            {
                result.AddException(e);
            }
            return(Json(result));
        }
Esempio n. 25
0
        public virtual ActionResult MoveFile(string folderName, string uuid, string targetFolder)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                ServiceFactory.MediaContentManager.Move(Repository, folderName, uuid, targetFolder, uuid);
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Esempio n. 26
0
        /// <summary>
        /// Sorts the pages.
        /// </summary>
        /// <param name="fullName">The full name. The parent page name</param>
        /// <param name="pageNames">The page names order</param>
        /// <returns></returns>
        public virtual ActionResult SortPages(string fullName, string[] pageNames)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                Manager.SortPages(Site, fullName, pageNames);
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return(Json(entry));
        }
Esempio n. 27
0
        public virtual ActionResult ResetPassword(ResetPasswordModel password)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);

            try
            {
                ServiceFactory.UserManager.ChangePassword(password.UserName, password.NewPassword);
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return(Json(resultEntry));
        }
Esempio n. 28
0
        public virtual ActionResult Top(string folderName, string uuid)
        {
            JsonResultEntry result = new JsonResultEntry();

            try
            {
                ServiceFactory.TextContentManager.Top(Repository, folderName, uuid);
            }
            catch (Exception e)
            {
                result.AddException(e);
            }

            return(Json(result));
        }
Esempio n. 29
0
        public virtual ActionResult MovePage(CopyPageModel model, string fullName, string parentPage)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                Manager.Move(Site, fullName, parentPage, model.CreateRedirect);
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return(Json(entry));
        }
Esempio n. 30
0
        public ActionResult Index(Setting setting)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);

            try
            {
                Kooboo.CMS.Account.Persistence.RepositoryFactory.SettingRepository.Update(setting, setting);
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return(Json(resultEntry));
        }