Пример #1
0
 public override ActionResult Create(CMS.Sites.Models.View model)
 {
     JsonResultEntry resultEntry = new JsonResultEntry() { Success = true };
     try
     {
         if (ModelState.IsValid)
         {
             model.UserName = User.Identity.Name;
             Add(model);
             var pageRedirect = Request.Form["pageRedirect"] ?? "";
             resultEntry.SetSuccess().RedirectUrl = pageRedirect.ToLower() == "false" ?
                 Url.Action("Edit", ControllerContext.RequestContext.AllRouteValues().Merge("Name", model.Name))
                 : Url.Action("Index", this.ControllerContext.RequestContext.AllRouteValues());
         }
         else
         {
             resultEntry.AddModelState(ModelState).SetFailed();
         }
     }
     catch (Exception e)
     {
         resultEntry.SetFailed().AddException(e);
     }
     resultEntry.AddModelState(ViewData.ModelState);
     return Json(resultEntry);
 }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
0
        public virtual ActionResult Edit(T newModel, string old_key)
        {
            JsonResultEntry resultEntry = new JsonResultEntry()
            {
                Success = true
            };

            try
            {
                if (ModelState.IsValid)
                {
                    Update(newModel, old_key);
                    //var fromPop = ControllerContext.RequestContext.GetRequestValue("FromPop");
                    //if (string.IsNullOrWhiteSpace(fromPop))
                    //{
                    //    return RedirectToIndex(newModel.ToString());
                    //}
                }
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return(Json(resultEntry));
        }
Пример #6
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);
        }
Пример #7
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));
        }
Пример #8
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));
        }
Пример #9
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));
        }
Пример #10
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            var resultEntry = new JsonResultEntry()
            {
                Success = false
            };

            try
            {
                if (Session != null)
                {
                    Session.UserState = null;
                    Session.SessionId = null;
                    Session.Session.Clear();
                }
                var abc = Sys_UserManager.Login(model.UserName, model.Password);
                if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (CUtils.IsNullOrEmpty(returnUrl) || returnUrl == "/")
                    {
                        var url = Url.ActionLocalized("Index", "Home", new { area = "Auth" });
                        returnUrl = url;
                    }
                    resultEntry.Success          = true;
                    resultEntry.RedirectToOpener = true;
                    resultEntry.RedirectUrl      = returnUrl;
                }
                else
                {
                    var exitsData = "Tên đăng nhập hoặc mật khẩu không hợp lệ!";
                    resultEntry.AddMessage(exitsData);
                }


                return(Json(resultEntry));
                // If we got this far, something failed, redisplay form
                //ModelState.AddModelError("", "The user name or password provided is incorrect.");
                //return View(model);
            }
            catch (ValidationException valEx)
            {
                foreach (var ver in valEx.ValidationErrors)
                {
                    resultEntry.AddFieldError(ver.FieldName, ver.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(this, e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return(Json(resultEntry));
        }
Пример #11
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));
        }
Пример #12
0
        public ActionResult ShowPopupChangePassword(string usercode)
        {
            var resultEntry = new JsonResultEntry()
            {
                Success = false
            };

            try
            {
                ViewBag.UserCode = usercode;
                return(JsonView("ShowPopupChangePassword", null));
            }
            catch (Exception ex)
            {
                resultEntry.SetFailed().AddException(this, ex);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return(JsonViewError("ShowPopupChangePassword", null, resultEntry));
        }
Пример #13
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));
        }
Пример #14
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));
        }
Пример #15
0
        public virtual ActionResult Create(T model)
        {
            JsonResultEntry resultEntry = new JsonResultEntry()
            {
                Success = true
            };

            try
            {
                if (ModelState.IsValid)
                {
                    Add(model);
                }
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return(Json(resultEntry));
        }
Пример #16
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));
        }
Пример #17
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));
        }
Пример #18
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));
        }
Пример #19
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));
        }
Пример #20
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));
        }
Пример #21
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));
        }
Пример #22
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));
        }