Ejemplo n.º 1
0
 public ActionResult OnPostAlterSinger(string StringID, string StringScore, string StringSequence, int Round, int GroupId)
 {
     //验证
     if ((StringID != null && int.TryParse(StringID, out int ID)) && (StringScore != null && float.TryParse(StringScore, out float Score)) && (StringSequence != null && int.TryParse(StringSequence, out int Sequence)) && Round != -1 && GroupId > 0 && GroupId <= 4)
     {
         string[]         keys      = { "sequence", string.Format("score{0}", Round.ToString()), "group_id" };
         string           specifier = string.Format("`ID`={0}", ID);
         MySqlIntegration sqlInteg  = new MySqlIntegration(Configuration.GetConnectionString("sql"));
         try
         {
             sqlInteg.MySqlSelect("singers", new[] { "*" }, specifier);
         }
         catch (MySqlException ex)
         {
             return(JsonThrow(ex));
         }
         if (sqlInteg.IntegratedResult.Count > 0)
         {
             try
             {
                 sqlInteg.MySqlUpdate("singers", keys, specifier, Sequence, Score.ToString(), GroupId);
             }
             catch (MySqlException ex)
             {
                 return(JsonThrow(ex));
             }
         }
         return(new JsonResult(sqlInteg.IntegratedResult.Count));
     }
     //返回错误
     return(Redirect("https://baidu.com"));
 }
Ejemplo n.º 2
0
        public ActionResult OnGetSingers()
        {
            MySqlIntegration sqlInteg = new MySqlIntegration(Configuration.GetConnectionString("sql"));

            try
            {
                sqlInteg.MySqlSelect("singers", new[] { "*" }, "1=1 ORDER BY sequence");
                if (sqlInteg.IntegratedResult.Count > 0)
                {
                    Singers = new List <Singer>();
                    sqlInteg.IntegratedResult.ForEach(element => {
                        Singer singer = null;
                        try
                        {
                            singer = new Singer(element);
                        }
                        catch (NullReferenceException ex)
                        {
                            throw (ex);
                        }
                        if (singer != null)
                        {
                            Singers.Add(singer);
                        }
                    });
                    return(new JsonResult(JsonConvert.SerializeObject(Singers)));
                }
            }
            catch (MySqlException ex)
            {
                JsonThrow(ex);
            }
            return(new JsonResult("[]"));
        }
Ejemplo n.º 3
0
        public void OnGet()
        {
            MySqlIntegration sqlInteg = new MySqlIntegration(Configuration.GetConnectionString("sql"));

            try
            {
                sqlInteg.MySqlSelect("singers", new[] { "*" }, "1=1 ORDER BY sequence");
            }
            catch (MySqlException ex)
            {
                ViewData["error"] = JsonConvert.SerializeObject(ex.Message);
            }
            if (sqlInteg.IntegratedResult != null && sqlInteg.IntegratedResult.Count > 0)
            {
                sqlInteg.IntegratedResult.ForEach(element => {
                    Singer singer = null;
                    try
                    {
                        singer = new Singer(element);
                    }
                    catch (NullReferenceException ex)
                    {
                        throw (ex);
                    }
                    if (singer != null)
                    {
                        Singers.Add(singer);
                    }
                });
            }
        }
Ejemplo n.º 4
0
        public void OnGetAsync()
        {
            MySqlIntegration selectInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            BasicClasses = new List <BasicClass>();
            //选取所有基础类型
            string[] keysBasicClass = { "ID", "title_unique", "title_display" };
            if (selectInteg.MySqlSelect("basic_class", keysBasicClass).Count > 0)
            {
                selectInteg.IntegratedResult.ForEach(basicClassObj =>
                {
                    BasicClasses.Add(new BasicClass
                    {
                        ID           = (int)basicClassObj["ID"],
                        UniqueTitle  = (string)basicClassObj["title_unique"],
                        DisplayTitle = (string)basicClassObj["title_display"]
                    });
                });
            }
            //选取对应的类
            string[] keys = { "*" };
            if (selectInteg.MySqlSelect("entries", keys, "title_unique=" + MySqlIntegration.QuoteStr((string)RouteData.Values["title"])).Count > 0)
            {
                var obj = selectInteg.IntegratedResult;
                PageEntry = new Entry()
                {
                    UniqueTitle  = (string)RouteData.Values["title"],
                    DisplayTitle = (string)obj[0]["title_display"],
                    BasicClassID = (int)obj[0]["basic_class_ID"],
                    PageContent  = (string)obj[0]["content"],
                    CreationTime = (DateTime)obj[0]["creation_time"],
                    //ModificationTime = (DateTime)(obj[0]["modification_time"]??new DateTime())
                };
                //var modificationTime = obj[0]["modification_time"];
            }
            else
            {
                PageEntry = new Entry()
                {
                    UniqueTitle = (string)RouteData.Values["title"],
                    PageContent = "<div class='paragraph tempintro'>Click edit to create the entry \"" + RouteData.Values["title"] + "\"</div>"
                };
                //通过比较UniqueTitle判断当前路径下的词条是否为基础类,若是,DisplayTitle采用BasicClass.DisplayTitle的值
                if (IsBasicEntry(PageEntry))
                {
                    BasicClass tempBasicClass = BasicClasses.Find(basicClassObj => basicClassObj.UniqueTitle == PageEntry.UniqueTitle);
                    PageEntry.DisplayTitle = tempBasicClass?.DisplayTitle;
                    PageEntry.BasicClassID = tempBasicClass.ID;
                }
                else
                {
                    PageEntry.DisplayTitle = PageEntry.UniqueTitle;
                }
            }
        }
Ejemplo n.º 5
0
        public ActionResult OnPostUploadFile(string title, IFormFile fileUpload)
        {
            IFormFile file = fileUpload;//Request.Form.Files[0];

            if ((file == null || file.Length == 0) || (title == null || title.Trim().Length == 0) || file.Length > 4194304)
            {
                return(new JsonResult(State.INVAILD_DATA));
            }

            MemoryStream memoryStream = new MemoryStream();

            file.CopyTo(memoryStream);
            string fileName   = Path.GetFileNameWithoutExtension(file.FileName);
            string extention  = Path.GetExtension(file.FileName);
            string localPath  = Path.Combine(Environment.WebRootPath, "files", title, fileName + extention);
            string serverPath = Path.Combine(Path.DirectorySeparatorChar.ToString(), "files", title, fileName + extention);

            Directory.CreateDirectory(Path.Combine(Environment.WebRootPath, "files", title));
            string[] keys = { "entry_title", "operator_type", "key_title", "value", "class" };

            MySqlIntegration sqlInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            sqlInteg.MySqlInsert("repo_key_values", keys, title, Operator.File, "file_title", fileName + extention, "string");
            sqlInteg.MySqlInsert("repo_key_values", keys, title, Operator.File, "file_web_path", serverPath.Replace("\\", "\\\\"), "string");

            keys = new string[] { "title_unique", "title_display", "operator_type", "owner" };
            sqlInteg.MySqlInsert("repo_entries", keys, title, title, Operator.File, "anonymous");

            //Future Feature
            //sqlInteg.MySqlInsert("repo_key_values", keys, title, Operator.File, "description", localPath, "string");
            System.Threading.Thread.Sleep(2500);
            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(localPath, FileMode.Create);
                file.CopyTo(fileStream);
            }
            catch (IOException ex)
            {
                Debug.WriteLine(ex.Message);
                return(new JsonResult(State.IO_ERROR));
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }

            return(new JsonResult(JsonConvert.SerializeObject(State.SUCCESS)));
        }
Ejemplo n.º 6
0
        public ActionResult OnPostSave()
        {
            MemoryStream memoryStream = new MemoryStream();

            Request.Body.CopyTo(memoryStream);
            memoryStream.Position = 0;
            using (StreamReader reader = new StreamReader(memoryStream))
            {
                string result = reader.ReadToEnd();
                if (result.Length > 0 || !result.Trim().Equals(""))
                {
                    PageEntry = JsonConvert.DeserializeObject <Entry>(result);
                }
                else
                {
                    return(new JsonResult(JsonConvert.SerializeObject(0)));
                }
            }
            //变量验证
            if (BasicClasses.Find(basicClassObj => basicClassObj.ID == PageEntry.BasicClassID) == null)
            {
                PageEntry.BasicClassID = 0;
            }
            else
            {
                if (IsBasicEntry(PageEntry))
                {
                    PageEntry.BasicClassID = BasicClasses.Find(basicClassObj => basicClassObj.UniqueTitle == PageEntry.UniqueTitle).ID;
                }
            }
            PageEntry.PageContent = PageEntry.PageContent.Replace("\\", "\\\\");
            PageEntry.PageContent = PageEntry.PageContent.Replace("\'", "\\\'");
            string[]         keySelect = { "title_unique" };
            MySqlIntegration postInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            postInteg.MySqlSelect("entries", keySelect, "title_unique=" + MySqlIntegration.QuoteStr(PageEntry.UniqueTitle));

            string[] keysSave = { "title_unique", "basic_class_ID", "title_display", "content" };
            int      lineAffected;

            if (postInteg.IntegratedResult.Count > 0)
            {
                lineAffected = postInteg.MySqlUpdate("entries", keysSave, "title_unique=" + MySqlIntegration.QuoteStr(PageEntry.UniqueTitle), PageEntry.UniqueTitle, PageEntry.BasicClassID, PageEntry.DisplayTitle, PageEntry.PageContent);
            }
            else
            {
                lineAffected = postInteg.MySqlInsert("entries", keysSave, PageEntry.UniqueTitle, PageEntry.BasicClassID, PageEntry.DisplayTitle, PageEntry.PageContent);
            }
            return(new JsonResult(JsonConvert.SerializeObject(lineAffected)));
        }
Ejemplo n.º 7
0
        public JsonResult OnPostFetchImage(string UniqueTitle)
        {
            MySqlIntegration sqlInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            string[] keys = { "title_unique", "image_name", "max(version)" };
            sqlInteg.MySqlSelect("images", keys, "title_unique= " + MySqlIntegration.QuoteStr(UniqueTitle) + " GROUP BY image_name");
            List <string> imgPaths = new List <string>();

            foreach (var obj in sqlInteg.IntegratedResult)
            {
                Debug.WriteLine(obj["max(version)"]);
                imgPaths.Add(Path.Combine(Path.DirectorySeparatorChar.ToString(), "uploads", UniqueTitle, (string)obj["image_name"], ((DateTime)obj["max(version)"]).ToString("yyyy-MM-dd HH-mm-ss") + Path.GetExtension((string)obj["image_name"])));
            }
            return(new JsonResult(JsonConvert.SerializeObject(imgPaths)));
        }
Ejemplo n.º 8
0
        public void OnGet()
        {
            MySqlIntegration sqlInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            BasicClasses = new List <BasicClass>();
            //选取所有基础类型
            string[] keysBasicClass = { "ID", "title_unique", "title_display", "fa_icon" };
            if (sqlInteg.MySqlSelect("basic_class", keysBasicClass).Count > 0)
            {
                sqlInteg.IntegratedResult.ForEach(basicClassObj =>
                {
                    BasicClasses.Add(new BasicClass
                    {
                        ID           = (int)basicClassObj["ID"],
                        UniqueTitle  = (string)basicClassObj["title_unique"],
                        DisplayTitle = (string)basicClassObj["title_display"],
                        FaIcon       = (string)basicClassObj["fa_icon"]
                    });
                });
            }
            ResultEntries = new List <Entry>();
            if (Query != null)
            {
                Query = Query.Replace("\\", "\\\\");
                Query = Query.Replace("\'", "\\\'");
                string queryString = "SELECT * FROM entries WHERE LOWER(title_unique) LIKE LOWER('%{0}%') UNION SELECT * FROM entries WHERE LOWER(title_display) LIKE LOWER('%{0}%') UNION SELECT * FROM entries WHERE LOWER(content) LIKE LOWER('%{0}%');";
                if (sqlInteg.MySqlQuery(string.Format(queryString, Query)).Count > 0)
                {
                    sqlInteg.IntegratedResult.ForEach(obj => {
                        ResultEntries.Add(new Entry
                        {
                            DisplayTitle = (string)obj?["title_display"],
                            UniqueTitle  = (string)obj?["title_unique"],
                            BasicClassID = (int)obj?["basic_class_ID"],
                            PageContent  = (string)obj?["content"],
                            CreationTime = (DateTime)obj?["creation_time"]
                        });
                    });
                }
                if (PageNum > ResultEntries.Count / ResultLimit || PageNum < 0)
                {
                    PageNum = 0;
                }
                PageLimit = ResultEntries.Count - PageNum * ResultLimit;
                //if (PageLimit > 15) PageLimit = 15;
            }
        }
Ejemplo n.º 9
0
        public JsonResult OnPostSaveImage(string UniqueTitle)
        {
            if (ImageUpload == null || ImageUpload.Length == 0)
            {
                return(new JsonResult(""));
            }

            //current version of the image uploaded
            string version = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            //The name of image
            string fileName = Path.GetFileName(ImageUpload.FileName);
            //The path of the image on the server
            string localPath = Path.Combine(Environment.WebRootPath, "uploads", UniqueTitle, fileName, version + Path.GetExtension(fileName));
            //The path of the image from wwwroot
            string serverPath = Path.Combine(Path.DirectorySeparatorChar.ToString(), "uploads", UniqueTitle, fileName, version + Path.GetExtension(fileName));

            Directory.CreateDirectory(Path.Combine(Environment.WebRootPath, "uploads", UniqueTitle, fileName));

            string[] keys = { "title_unique", "image_name", "version" };

            MySqlIntegration sqlInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            sqlInteg.MySqlInsert("images", keys, UniqueTitle, fileName, version);
            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(localPath, FileMode.Create);
                ImageUpload.CopyTo(fileStream);
            }
            catch (IOException ex)
            {
                Debug.WriteLine(ex.Message);
                return(new JsonResult(""));
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
            return(new JsonResult(JsonConvert.SerializeObject(serverPath)));
        }
Ejemplo n.º 10
0
        public void OnGetAsync()
        {
            MySqlIntegration selectInteg = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));

            BasicClasses = new List <BasicClass>();
            string[] keys = { "ID", "title_unique", "title_display", "description", "fa_icon", "style" };
            selectInteg.MySqlSelect("basic_class", keys).ForEach(obj =>
            {
                BasicClass basicClass = new BasicClass
                {
                    ID           = (int)obj["ID"],
                    UniqueTitle  = (string)obj["title_unique"],
                    DisplayTitle = (string)obj["title_display"],
                    Description  = (string)obj["description"],
                    FaIcon       = (string)obj["fa_icon"],
                    Style        = (int)obj["style"]
                };
                BasicClasses.Add(basicClass);
            });
            Debug.WriteLine(Request.QueryString);
        }
Ejemplo n.º 11
0
 public void OnGet()
 {
     if ((string)RouteData.Values["title"] != null)
     {
         string           title     = (string)RouteData.Values["title"];
         string[]         keys      = { "*" };
         string           specifier = string.Format("entry_title={0} AND operator_type={1}", MySqlIntegration.QuoteStr(title), MySqlIntegration.QuoteStr(Operator.File));
         MySqlIntegration sqlInteg  = new MySqlIntegration(Configuration.GetConnectionString("MySqlConnection"));
         var result = sqlInteg.MySqlSelect("repo_key_values", keys, specifier);
         Debug.WriteLine(result.Count);
         RepoFile repoFile = new RepoFile();
         result.ForEach((element) => {
             if (element["key_title"].Equals("file_title"))
             {
                 repoFile.Title = (string)element["value"];
             }
             if (element["key_title"].Equals("file_web_path"))
             {
                 repoFile.Path = (string)element["value"];
             }
         });
         FileList.Add(repoFile);
     }
 }