예제 #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);
        }
예제 #2
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);
        }
예제 #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 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);
        }
예제 #5
0
        public virtual ActionResult Create(ReceivingSetting model, string repository)
        {
            var entry = new JsonResultEntry();
            if (ModelState.IsValid)
            {
                try
                {
                    Manager.Add(Repository, model);
                    entry.SetSuccess();
                }
                catch (Exception e)
                {
                    entry.AddException(e);
                }
            }
            else
            {
                entry.AddModelState(ModelState);
            }

            return Json(entry);
        }
예제 #6
0
        public virtual ActionResult Create(SendingSetting sendingSetting)
        {
            var entry = new JsonResultEntry();
            try
            {
                if (ModelState.IsValid)
                {
                    Manager.Add(Repository, sendingSetting);

                    entry.SetSuccess();
                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }
예제 #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);
        }
예제 #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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
0
        public virtual ActionResult Edit(SearchSetting model)
        {
            var entry = new JsonResultEntry();

            try
            {
                if (ModelState.IsValid)
                {
                    model.Repository = Repository;
                    Provider.Update(model, model);
                    entry.SetSuccess();
                }
                else
                {
                    entry.AddModelState(ModelState).SetFailed();
                }

            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }
예제 #13
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);
        }
예제 #14
0
        public virtual ActionResult ImportSite(ImportSiteModel model, bool uploadNew)
        {
            var entry = new JsonResultEntry();

            Site parent = null;
            if (!string.IsNullOrEmpty(model.Parent))
            {
                parent = new Site(model.Parent);
            }

            try
            {
                if (ModelState.IsValid)
                {

                    if (uploadNew)
                    {
                        if (!Request.Files[0].FileName.EndsWith(".zip"))
                        {
                            throw new KoobooException("Please upload an zip file".Localize());
                        }

                        ServiceFactory.SiteManager.Create(parent, model.Name, model.Repository, Request.Files[0].InputStream, User.Identity.Name);
                    }
                    else
                    {
                        ServiceFactory.SiteManager.Import(parent, model.Name, model.Repository, model.File, User.Identity.Name);
                    }
                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }
예제 #15
0
        public virtual ActionResult ImportRepository(string siteName, ImportRepositoryModel model, bool uploadNew)
        {
            var entry = new JsonResultEntry();

            try
            {
                var site = new Site(siteName).AsActual();

                if (site != null && ModelState.IsValid)
                {
                    Kooboo.CMS.Content.Models.Repository repository = null;
                    if (uploadNew)
                    {
                        if (!Request.Files[0].FileName.EndsWith(".zip"))
                        {
                            throw new KoobooException("Please upload an zip file".Localize());
                        }

                        repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Name, Request.Files[0].InputStream);
                    }
                    else
                    {
                        repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Name, model.File);
                    }

                    if (repository != null)
                    {
                        site.Repository = repository.Name;
                        ServiceFactory.SiteManager.Update(site);
                    }
                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }
예제 #16
0
 public virtual ActionResult Edit(SendingSetting @new)
 {
     var entry = new JsonResultEntry();
     try
     {
         if (ModelState.IsValid)
         {
             @new.Repository = Repository;
             Manager.Update(Repository, @new, @new);
             entry.SetSuccess();
         }
         else
         {
             entry.AddModelState(ModelState);
         }
     }
     catch (Exception e)
     {
         entry.AddException(e);
     }
     return Json(entry);
 }