Пример #1
0
        public IActionResult Index()
        {
            string projectPath = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder());
            string command     = Request.Query["command"];
            string path        = HttpUtility.UrlDecode(Request.Query["path"]);

            if (!string.IsNullOrEmpty(command) && !string.IsNullOrEmpty(path))
            {
                string[] folders = path.Split('/', '\\');

                if (command == "create")
                {
                    if (folders.Length == 1)
                    {
                        CreateCategory(folders[0], projectPath);
                    }
                    else if (folders.Length == 2)
                    {
                        CreateProduct(folders[1], Path.Combine(projectPath, folders[0]));
                    }
                    else if (folders.Length == 3)
                    {
                        CreateScenario(folders[2], Path.Combine(projectPath, folders[0], folders[1]));
                    }
                }
                else if (command == "remove")
                {
                    if (folders.Length > 0 && folders.Length <= 3)
                    {
                        RemoveFolder(Path.Combine(projectPath, folders[0]));
                    }
                    else if (folders.Length == 4)
                    {
                        RemoveTopic(Path.Combine(projectPath, folders[0], folders[1], folders[2]), folders[3]);
                    }
                }
                else if (command == "draft")
                {
                    if (folders.Length == 3)
                    {
                        Publishing.Draft(Path.Combine(projectPath, path), (res) => { Content("result: " + res); });
                    }
                }
                else if (command == "publish")
                {
                    if (folders.Length == 3)
                    {
                        Publishing.Publish(Path.Combine(projectPath, path), (res) => { });

                        return(Ok());
                    }
                }
                else if (command == "edit")
                {
                    if (folders.Length > 0 && folders.Length <= 2)
                    {
                        string newName = Request.Query["name"];
                        if (!string.IsNullOrEmpty(newName))
                        {
                            EditInfo(Path.Combine(projectPath, path), newName);
                        }
                    }
                    else if (folders.Length == 3)
                    {
                        string newName = Request.Query["name"];
                        string newDesc = Request.Query["desc"];
                        if (!string.IsNullOrEmpty(newName) || !string.IsNullOrEmpty(newDesc))
                        {
                            EditInfo(Path.Combine(projectPath, path), newName, newDesc);
                        }
                    }
                    else if (folders.Length == 4)
                    {
                        string to        = Request.Query["to"];
                        string topicPath = path.Replace(folders[3], "topics");
                        if (!string.IsNullOrEmpty(to))
                        {
                            EditTopicIndex(Path.Combine(projectPath, topicPath), folders[3], int.Parse(to));
                        }
                        else if (Request.Form.Files.Count > 0)
                        {
                            string newPathToZip = Path.Combine(projectPath,
                                                               path.Replace(folders[3],
                                                                            Path.Combine("default", "pub_in", Request.Form.Files[0].FileName)));
                            if (!IOFile.Exists(newPathToZip))
                            {
                                using (var fileStream = new FileStream(newPathToZip, FileMode.Create))
                                {
                                    Request.Form.Files[0].CopyTo(fileStream);
                                }

                                EditZipPath(Path.Combine(projectPath, topicPath, folders[3] + ".info"), newPathToZip);
                            }
                        }
                        else
                        {
                            return(Content("wrong data"));
                        }
                    }
                }
            }

            return(new StatusCodeResult(302));
        }