Beispiel #1
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));
        }
Beispiel #2
0
        public override ActionResult Edit(Layout newModel, string old_key)
        {
            JsonResultEntry resultEntry = new JsonResultEntry()
            {
                Success = true
            };

            try
            {
                if (ModelState.IsValid)
                {
                    newModel.UserName = User.Identity.Name;

                    Update(newModel, old_key);
                    resultEntry.SetSuccess();
                    //resultEntry.RedirectUrl = this.Url.Action("Index", this.ControllerContext.RequestContext.AllRouteValues());

                    var pageRedirect = Request.Form["pageRedirect"];
                    resultEntry.AddMessage("The item has been saved.".Localize()).SetSuccess().RedirectUrl = string.Equals(pageRedirect, "true", StringComparison.OrdinalIgnoreCase) ? this.Url.Action("Index", this.ControllerContext.RequestContext.AllRouteValues()) : null;
                }
            }
            catch (Exception e)
            {
                resultEntry.SetFailed().AddException(e);
            }
            resultEntry.AddModelState(ViewData.ModelState);
            return(Json(resultEntry));
        }
Beispiel #3
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));
        }
Beispiel #4
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));
        }
Beispiel #5
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));
        }
Beispiel #6
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));
        }
Beispiel #7
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();
        }
Beispiel #8
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");
        }
Beispiel #9
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);
 }
Beispiel #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));
        }
Beispiel #11
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));
        }
Beispiel #12
0
        public virtual ActionResult Unlocalize(T o)
        {
            var entry = new JsonResultEntry();

            try
            {
                Remove(o);
                entry.RedirectUrl = GetReturnUrl();
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }

            return(Json(entry));
        }
        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));
        }
Beispiel #14
0
        public virtual ActionResult Delete(T[] model)
        {
            var entry = new JsonResultEntry();

            try
            {
                foreach (var t in model)
                {
                    Remove(t);
                }
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }

            return(Json(entry));
        }
Beispiel #15
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));
        }
Beispiel #16
0
        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));
        }
Beispiel #17
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));
        }
Beispiel #18
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));
        }
Beispiel #19
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));
        }
Beispiel #20
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));
        }
Beispiel #21
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));
        }
Beispiel #22
0
        public override ActionResult Create(Page model)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                if (ModelState.IsValid)
                {
                    var  parentPage = ControllerContext.RequestContext.GetRequestValue("parentPage");
                    Page parent     = null;
                    if (!string.IsNullOrWhiteSpace(parentPage))
                    {
                        parent = PageHelper.Parse(Site, parentPage);
                    }

                    model.Parent = parent;

                    SavePosition(model);

                    model.UserName = User.Identity.Name;

                    Manager.Add(Site, parentPage, model);

                    entry.SetSuccess();

                    entry.RedirectUrl = GetReturnUrl();
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
                entry.SetFailed();
            }

            return(Json(entry));
        }
Beispiel #23
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));
        }
        public ActionResult ChangePassword(string usercode, string passnew, string confpass)
        {
            var resultEntry = new JsonResultEntry()
            {
                Success = false
            };
            var userState = this.UserState;

            try
            {
                var title = "";
                if (!CUtils.IsNullOrEmpty(usercode))
                {
                    if (!CUtils.IsNullOrEmpty(passnew))
                    {
                        passnew = passnew.Trim();
                        if (!CUtils.IsNullOrEmpty(confpass))
                        {
                            confpass = confpass.Trim();
                            if (passnew.Equals(confpass))
                            {
                                var sysUser = Sys_UserManager.Get(new Sys_User()
                                {
                                    UserCode = usercode
                                });

                                if (sysUser != null)
                                {
                                    var salt     = EncryptUtils.GenerateSalt();
                                    var password = EncryptUtils.EncryptPassword(passnew, salt);

                                    sysUser.Password     = password.Trim();
                                    sysUser.PasswordSalt = salt.Trim();
                                    sysUser.UpdateBy     = userState.SysUser.UserCode;

                                    Sys_UserManager.Add(sysUser);
                                    title = "Thay đổi mật khẩu thành công!";

                                    resultEntry.RedirectUrl = Url.Action("LogOff", "Account", new { area = "Auth" });
                                }
                                else
                                {
                                    title = "Mã người dùng '" + usercode + "' không có trong hệ thống!";
                                }
                            }
                            else
                            {
                                title = "Nhập lại mật khẩu mới không đúng, Vui lòng nhập lại!";
                            }
                        }
                        else
                        {
                            title = "Nhập lại khẩu mới trống!";
                        }
                    }
                    else
                    {
                        title = "Mật khẩu mới trống!";
                    }
                }
                else
                {
                    title = "Mã người dùng trống!";
                }

                resultEntry.Success = true;
                resultEntry.AddMessage(title);
            }
            catch (Exception ex)
            {
                resultEntry.SetFailed().AddException(this, ex);
            }
            return(Json(resultEntry));
        }
Beispiel #25
0
        public virtual ActionResult DeleteSelect(string folderName, string[] folders, string[] files)
        {
            var entry = new JsonResultEntry();

            try
            {
                if (string.IsNullOrWhiteSpace(folderName))
                {
                    if (folders != null)
                    {
                        foreach (var f in folders)
                        {
                            if (string.IsNullOrEmpty(f))
                            {
                                continue;
                            }
                            var folderPath = FolderHelper.SplitFullName(f);
                            FolderManager.Remove(Repository, new MediaFolder(Repository, folderPath));
                        }
                    }
                }
                else
                {
                    var folder = FolderManager.Get(Repository, folderName).AsActual();
                    if (folders != null)
                    {
                        foreach (var f in folders)
                        {
                            if (string.IsNullOrEmpty(f))
                            {
                                continue;
                            }
                            var folderPath = FolderHelper.SplitFullName(f);
                            FolderManager.Remove(Repository, new MediaFolder(Repository, folderPath));
                        }
                    }

                    if (files != null)
                    {
                        foreach (var f in files)
                        {
                            if (string.IsNullOrEmpty(f))
                            {
                                continue;
                            }
                            ContentManager.Delete(Repository, folder, f);
                        }
                    }
                }

                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.SetFailed().AddException(e);
            }

            return(Json(entry));

            //return RedirectToAction("Index", new { folderName = folderName });
        }