Example #1
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);
        }
Example #2
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");
        }
Example #3
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);
        }
        public virtual ActionResult Delete(PagePublishingQueueItem[] model)
        {
            var result = new JsonResultEntry();
            try
            {
                foreach (var item in model)
                {
                    item.Site = Site;
                    ServiceFactory.PageManager.PagePublishingProvider.Remove(item);
                }
                result.SetSuccess();
            }
            catch (Exception e)
            {
                result.SetFailed().AddException(e);
            }

            return Json(result);
        }
Example #5
0
        public virtual ActionResult Create(CreateRepositoryModel model)
        {
            JsonResultEntry resultEntry = new JsonResultEntry() { Success = true };
            try
            {
                if (ModelState.IsValid)
                {
                    ServiceFactory.RepositoryManager.Create(model.Name, model.Template);
                    resultEntry.RedirectUrl = Url.Action("Index", new { controller = "home", repositoryName = model.Name });
                }

            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return Json(resultEntry);
        }
Example #6
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);
        }
Example #7
0
        public virtual ActionResult Edit(string folderName, string parentFolder, string uuid, FormCollection form, bool? localize)
        {
            JsonResultEntry resultEntry = new JsonResultEntry() { Success = true };
            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;
                    //if (textFolder != null)
                    //{
                    content = ServiceFactory.TextContentManager.Update(Repository, textFolder, uuid, form,
                    Request.Files, DateTime.UtcNow, addedCategories, removedCategories, User.Identity.Name);

                    if (localize.HasValue && localize.Value == true)
                    {
                        ServiceFactory.TextContentManager.Localize(textFolder, uuid);
                    }
                    //}
                    //else
                    //{
                    //    content = ServiceFactory.TextContentManager.Update(Repository, schema, uuid, form,
                    //    Request.Files, User.Identity.Name);
                    //}

                    resultEntry.Success = true;
                }
            }
            catch (RuleViolationException violationException)
            {
                foreach (var item in violationException.Issues)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
                resultEntry.Success = false;
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return Json(resultEntry);
        }
Example #8
0
        public virtual ActionResult Create(string folderName, string parentFolder, string parentUUID, FormCollection form)
        {
            JsonResultEntry resultEntry = new JsonResultEntry() { Success = true };
            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 = ServiceFactory.TextContentManager.Add(Repository, textFolder, parentFolder, parentUUID, form, Request.Files, addedCategories, User.Identity.Name);

                    resultEntry.ReloadPage = true;

                    resultEntry.Success = true;
                }
            }
            catch (RuleViolationException ruleEx)
            {
                foreach (var item in ruleEx.Issues)
                {
                    resultEntry.AddFieldError(item.PropertyName, item.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return Json(resultEntry);
        }
Example #9
0
        public virtual ActionResult Delete(string[] model)
        {
            var entry = new JsonResultEntry();
            try
            {
                foreach (var f in model)
                {
                    if (string.IsNullOrEmpty(f)) continue;
                    var folderPathArr = FolderHelper.SplitFullName(f);
                    Manager.Remove(Repository, new TextFolder(Repository, folderPathArr));
                }
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }
            return Json(entry);

            //return RedirectToIndex();
        }
Example #10
0
        public virtual ActionResult Edit(TextFolder model, string fullName, string successController)
        {
            JsonResultEntry resultEntry = new JsonResultEntry() { Success = true };
            try
            {
                if (ModelState.IsValid)
                {
                    fullName = string.IsNullOrEmpty(fullName) ? model.FullName : fullName;
                    var old = Manager.Get(Repository, fullName);
                    model.Parent = old.Parent;
                    Manager.Update(Repository, model, old);

                    var fromPop = ControllerContext.RequestContext.GetRequestValue("FromPop");

                    resultEntry.Success = true;
                }

            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return Json(resultEntry);
        }
Example #11
0
 public virtual ActionResult Delete(string selectedFolders)
 {
     var entry = new JsonResultEntry();
     try
     {
         var folderArr = selectedFolders.Split(',');
         foreach (var f in folderArr)
         {
             if (string.IsNullOrEmpty(f)) continue;
             FolderManager.Remove(Repository, new MediaFolder(Repository, f));
         }
         entry.SetSuccess();
     }
     catch (Exception e)
     {
         entry.SetFailed().AddException(e);
     }
     return Json(entry);
 }
Example #12
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);
 }
Example #13
0
        public virtual ActionResult ResetTemplates(Schema[] model)
        {
            JsonResultEntry entry = new JsonResultEntry();
            try
            {
                if (model != null)
                {
                    foreach (var item in model)
                    {
                        ResetAllForm(item.Name);
                    }
                    entry.AddMessage("The templates have been reset.".Localize());
                }
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }

            return Json(entry);
        }
Example #14
0
        public virtual ActionResult Delete(Schema[] model)
        {
            JsonResultEntry entry = new JsonResultEntry();
            try
            {
                if (model != null)
                {
                    foreach (var item in model)
                    {
                        Manager.Remove(Repository, new Schema(Repository, item.Name));
                    }
                }
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }

            return Json(entry);
        }