예제 #1
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;
                }
            }
        }
예제 #2
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)));
        }
예제 #3
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)));
        }
예제 #4
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);
     }
 }