Пример #1
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);
        }
Пример #2
0
        public virtual ActionResult BatchPublish(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[] { true }, User.Identity.Name);
                    }

                }

                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        public virtual ActionResult Delete(AssemblyFile[] model)
        {
            var entry = new JsonResultEntry();
            try
            {
                if (model != null)
                {
                    foreach (var fileName in model)
                    {
                        if (!string.IsNullOrEmpty(fileName.FileName))
                        {
                            AssemblyManager.Delete(Site, fileName.FileName);
                        }
                    }
                }
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }
            return Json(entry);

            //return RedirectToAction("Index");
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
0
 public virtual ActionResult Delete(string directoryPath, IEnumerable<string> filePaths, IEnumerable<string> directoryPaths)
 {
     var entry = new JsonResultEntry();
     try
     {
         if (filePaths != null)
         {
             foreach (var f in filePaths)
             {
                 FileManager.DeleteFile(Site, f);
             }
         }
         if (directoryPaths != null)
         {
             foreach (var d in directoryPaths)
             {
                 FileManager.DeleteDirectory(Site, d);
             }
         }
         //entry.SetSuccess();
     }
     catch (Exception e)
     {
         entry.SetFailed().AddException(e);
     }
     return Json(entry);
 }
Пример #10
0
        public virtual ActionResult Create(TextFolder model, string folderName)
        {
            //compatible with the Folder parameter changed to FolderName.
            folderName = folderName ?? this.ControllerContext.RequestContext.GetRequestValue("Folder");

            JsonResultEntry resultEntry = new JsonResultEntry() { Success = true };
            try
            {
                if (ModelState.IsValid)
                {
                    Folder parent = null;
                    if (!string.IsNullOrEmpty(folderName))
                    {
                        parent = FolderHelper.Parse<TextFolder>(Repository, folderName);
                    }
                    model.Parent = parent;
                    model.UtcCreationDate = DateTime.UtcNow;
                    Manager.Add(Repository, model);

                    resultEntry.Success = true;

                    return Json(resultEntry);
                }
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return Json(resultEntry);
        }
Пример #11
0
        protected override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                var result = new JsonResultEntry();
                result.AddException(filterContext.Exception);
                filterContext.Result = Json(result, JsonRequestBehavior.AllowGet);
                filterContext.ExceptionHandled = true;
            }
        }
Пример #12
0
        protected override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                var result = new JsonResultEntry();
                result.AddException(filterContext.Exception);
                filterContext.Result           = Json(result, JsonRequestBehavior.AllowGet);
                filterContext.ExceptionHandled = true;
            }
        }
Пример #13
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);
 }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
0
 public virtual ActionResult Index(string body)
 {
     JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
     try
     {
         Robots_Txt robot_txt = new Robots_Txt(Site);
         robot_txt.Save(body);
         resultEntry.AddMessage("The robots.txt has been saved.".Localize());
     }
     catch (Exception e)
     {
         resultEntry.AddException(e);
     }
     return Json(resultEntry);
 }
Пример #17
0
 public virtual ActionResult Create(SearchSetting model)
 {
     var entry = new JsonResultEntry();
     try
     {
         model.Repository = Repository;
         Provider.Add(model);
         entry.SetSuccess();
     }
     catch (Exception e)
     {
         entry.AddException(e);
     }
     return Json(entry);
 }
Пример #18
0
 public virtual ActionResult Rebuild(string folderName)
 {
     var entry = new JsonResultEntry();
     try
     {
         var textFolder = new TextFolder(Repository, folderName);
         IndexSummaryService.Instance.Rebuild(textFolder);
         entry.RedirectUrl = Url.Action("Index", Request.RequestContext.AllRouteValues());
     }
     catch (Exception e)
     {
         entry.AddException(e);
     }
     return Json(entry);
 }
Пример #19
0
        public virtual ActionResult Delete(Workflow[] model)
        {
            var entry = new JsonResultEntry();
            try
            {
                Manager.Delete(model, Repository);
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return Json(entry);
        }
Пример #20
0
        public virtual ActionResult Index(Site model)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
            try
            {
                if (ModelState.IsValid)
                {
                    var site = Site.AsActual();

                    //if (isNew)
                    //{
                    //    CreateRepository(model.Repository);
                    //}

                    site.DisplayName = model.DisplayName;
                    site.Culture = model.Culture;

                    site.Domains = model.Domains;
                    site.SitePath = model.SitePath;
                    site.Mode = model.Mode;
                    site.Repository = model.Repository;
                    site.Theme = model.Theme;
                    site.Version = model.Version;
                    site.InlineEditing = model.InlineEditing;
                    site.ShowSitemap = model.ShowSitemap;
                    site.Smtp = model.Smtp;
                    site.Security = model.Security;
                    site.ResourceDomain = model.ResourceDomain;
                    if (site.Smtp != null && site.Smtp.To != null)
                    {
                        site.Smtp.To = site.Smtp.To.Where(it => !string.IsNullOrEmpty(it)).ToArray();
                    }
                    site.CustomFields = model.CustomFields;
                    site.EnableVersioning = model.EnableVersioning;
                    site.EnableJquery = model.EnableJquery;
                    site.EnableStyleEdting = model.EnableStyleEdting;

                    ServiceFactory.SiteManager.Update(site);
                    resultEntry.AddMessage("Site setting has been changed.".Localize());
                }

            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }
            return Json(resultEntry);
        }
Пример #21
0
        public virtual ActionResult Process(string workflowName,string roleName, string name, bool passed, string comment)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                Manager.ProcessPendingWorkflowItem(Repository, workflowName,roleName, name, User.Identity.Name, passed, comment);
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return Json(entry);
        }
Пример #22
0
        public virtual ActionResult CreateFile(string directoryPath, string name, string fileExtension, string body)
        {
            JsonResultEntry result = new JsonResultEntry(ModelState);
            try
            {
                string fileName = name + fileExtension ?? "";

                FileManager.AddFile(Site, directoryPath, fileName, body);

            }
            catch (Exception e)
            {
                result.AddException(e);
            }
            return Json(result);
        }
Пример #23
0
        public virtual ActionResult Copy(string sourceName, string destName)
        {
            var entry = new JsonResultEntry();
            try
            {
                Manager.Copy(Repository, sourceName, destName);
                entry.RedirectUrl = Url.Action("Index", ControllerContext.RequestContext.AllRouteValues());
                entry.ReloadPage = true;
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return Json(entry);
        }
Пример #24
0
        public virtual ActionResult UpdateContent(string schema, string uuid, string fieldName, string value)
        {
            var result = new JsonResultEntry();
            try
            {
                var schemaObject = new Schema(Repository.Current, schema).AsActual();

                var fieldValue = Kooboo.CMS.Content.Models.Binder.TextContentBinder.DefaultBinder.ConvertToColumnType(schemaObject, fieldName, value);

                Kooboo.CMS.Content.Services.ServiceFactory.TextContentManager.Update(Repository.Current, schemaObject, uuid, fieldName, fieldValue, User.Identity.Name);
            }
            catch (Exception e)
            {
                result.AddException(e);
            }
            return Json(result);
        }
Пример #25
0
        public virtual ActionResult Delete(Role[] model)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
            try
            {
                foreach (var role in model)
                {
                    ServiceFactory.RoleManager.Delete(role.Name);
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return Json(resultEntry);
        }
Пример #26
0
        public virtual ActionResult Edit(CreateRoleModel model)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
            try
            {
                if (ModelState.IsValid)
                {
                    ServiceFactory.RoleManager.Update(model.Name, model.ToRole());
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return Json(resultEntry);
        }
Пример #27
0
 public virtual ActionResult Index(Repository model)
 {
     JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
     try
     {
         if (ModelState.IsValid)
         {
             RepositoryManager.Update(model, RepositoryManager.Get(model.Name));
             resultEntry.AddMessage("Database setting has been changed.".Localize());
         }
     }
     catch (Exception e)
     {
         resultEntry.AddException(e);
     }
     return Json(resultEntry);
 }
Пример #28
0
 public ActionResult Delete(News[] model)
 {
     JsonResultEntry resultEntry = new JsonResultEntry();
     try
     {
         foreach (var item in model)
         {
             repository.Delete(item);
         }
         resultEntry.RedirectUrl = Url.Action("Index", ControllerContext.RequestContext.AllRouteValues().Merge("id", null));
     }
     catch (Exception e)
     {
         resultEntry.AddException(e);
     }
     return Json(resultEntry);
 }
Пример #29
0
        public virtual ActionResult Create(CreateUserModel model, FormCollection collection)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
            try
            {
                if (ModelState.IsValid)
                {
                    ServiceFactory.UserManager.Add(model.ToUser());
                }
            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return Json(resultEntry);
        }
Пример #30
0
        public ActionResult Index(string siteName, ModuleInfo_Metadata moduleInfo)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
            try
            {
                if (ModelState.IsValid)
                {
                    ModuleInfo.SaveModuleSetting(ModuleName, siteName, moduleInfo.Settings);
                    resultEntry.AddMessage("Module setting has been changed.".Localize());
                }

            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }
            return Json(resultEntry);
        }
Пример #31
0
        public ActionResult Create(News news)
        {
            JsonResultEntry resultEntry = new JsonResultEntry(ViewData.ModelState);
            try
            {
                if (ModelState.IsValid)
                {
                    repository.Add(news);
                    resultEntry.RedirectUrl = Url.Action("Index", this.ControllerContext.RequestContext.AllRouteValues());
                }

            }
            catch (Exception e)
            {
                resultEntry.AddException(e);
            }

            return Json(resultEntry);
        }