Example #1
0
        public void TestTest()
        {
            APPStoreInfo diHaoV1_API = new APPStoreInfo()
            {
                resp_data = new Resp_Data()
                {
                    app_list = new AppInfo[]
                    {
                        new AppInfo()
                        {
                            appid      = 111,
                            appautor   = "appid",
                            appdetail  = "appid",
                            appname    = "appid",
                            apppackage = "appid",
                            appdownurl = "appid",
                            applogourl = "appid",
                            appversion = "appid",
                            imglist    = new string[] { "", "" },
                            appsize    = "appid"
                        }
                    }
                }
            };
            string json = JsonSerializer.Serialize(diHaoV1_API, MyJsonConvert.GetOptions());

            Console.WriteLine(json);
        }
Example #2
0
        //修改笔记
        public IActionResult UpdateNotebook(string token, string notebookId, string title, string parentNotebookId, int seq, int usn)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                Notebook notebook;
                if (NotebookService.UpdateNotebookApi(user.UserId, MyConvert.HexToLong(notebookId), title, MyConvert.HexToLong(parentNotebookId), seq, usn, out notebook))
                {
                    ApiNotebook apiNotebook = fixNotebook(notebook);

                    return(Json(apiNotebook, MyJsonConvert.GetOptions()));
                }
                else
                {
                    ApiRe apiRe = new ApiRe()
                    {
                        Ok  = false,
                        Msg = "UpdateNotebook is error",
                    };

                    return(Json(apiRe, MyJsonConvert.GetOptions()));
                }
            }
        }
        //todo:格式化URL

        //todo:得到内容
        public IActionResult GetNoteContent(string token, string noteId)
        {
            ApiRe falseRe = new ApiRe()
            {
                Ok  = false,
                Msg = "GetNoteContent_is_error"
            };
            Note        note        = NoteService.GetNote(MyConvert.HexToLong(noteId), getUserIdByToken(token));
            NoteContent noteContent = NoteContentService.GetNoteContent(MyConvert.HexToLong(noteId), getUserIdByToken(token), false);

            if (noteContent == null || note == null)
            {
                return(Json(falseRe, MyJsonConvert.GetOptions()));
            }
            if (noteContent != null && !string.IsNullOrEmpty(noteContent.Content))
            {
                noteContent.Content = NoteService.FixContent(noteContent.Content, note.IsMarkdown);
            }
            ApiNoteContent apiNote = new ApiNoteContent()
            {
                NoteId  = note.NoteId,
                UserId  = note.UserId,
                Content = noteContent.Content
            };

            return(Json(apiNote, MyJsonConvert.GetOptions()));
        }
Example #4
0
        public IActionResult ListNotes(string notebookId)
        {
            Note[] notes = NoteService.ListNotes(1208692382644703232, 1208692382640508928, false, 1, 1, "defaultSortField", false, false);
            string json  = JsonSerializer.Serialize(notes, MyJsonConvert.GetOptions());

            return(Content(json));
        }
Example #5
0
        //todo:删除笔记本
        public IActionResult DeleteNotebook(string token, string notebookId, int usn)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            if (NotebookService.DeleteNotebookForce(user.UserId, MyConvert.HexToLong(notebookId), usn))
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = true,
                    Msg = "success",
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "conflict",
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
        }
        //todo:得到note和内容
        public IActionResult GetNoteAndContent(string token, string noteId)
        {
            User tokenUser = TokenSerivce.GetUserByToken(token);

            if (tokenUser == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ""
                }, MyJsonConvert.GetOptions()));
            }
            NoteAndContent noteAndContent = NoteService.GetNoteAndContent(MyConvert.HexToLong(noteId), tokenUser.UserId, false, false, false);

            ApiNote[] apiNotes = NoteService.ToApiNotes(new Note[] { noteAndContent.note });
            ApiNote   apiNote  = apiNotes[0];

            apiNote.Content  = NoteService.FixContent(noteAndContent.noteContent.Content, noteAndContent.note.IsMarkdown);
            apiNote.Desc     = noteAndContent.note.Desc;
            apiNote.Abstract = noteAndContent.noteContent.Abstract;
            if (noteAndContent == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ""
                }, MyJsonConvert.GetOptions()));
            }
            else
            {
                return(Json(apiNote, MyJsonConvert.GetOptions()));
            }
        }
Example #7
0
        public void GetNoteBookTreeTest()
        {
            Notebook[] notebooks = NotebookService.GetNoteBookTree(1208692382644703232);
            string     json      = JsonSerializer.Serialize(notebooks, MyJsonConvert.GetOptions());

            Console.WriteLine(json);
            // Assert.Fail();
        }
 //todo:获取同步的笔记
 //public JsonResult GetSyncNotes([ModelBinder(BinderType = typeof(Hex2LongModelBinder))]long userId,int afterUsn,int maxEntry,string token)
 //{
 //    if (maxEntry==0) maxEntry=100;
 //    ApiNote[] apiNotes=NoteService.GetSyncNotes(userId,afterUsn,maxEntry);
 //    return Json(apiNotes,MyJsonConvert.GetOptions());
 //}
 public JsonResult GetSyncNotes(int afterUsn, int maxEntry, string token)
 {
     if (maxEntry == 0)
     {
         maxEntry = 100;
     }
     ApiNote[] apiNotes = NoteService.GetSyncNotes(getUserIdByToken(token), afterUsn, maxEntry);
     return(Json(apiNotes, MyJsonConvert.GetOptions()));
 }
Example #9
0
        public IActionResult GetNotebooks()
        {
            long userid = 1208692382644703232;

            Notebook[] noteBoooks = NotebookService.GetNoteBookTree(userid);
            string     json       = JsonSerializer.Serialize(noteBoooks, MyJsonConvert.GetOptions());

            return(Content(json));
        }
Example #10
0
        public static string GetPolicy(UPYunOSSOptions options)
        {
            string json = JsonSerializer.Serialize(options, MyJsonConvert.GetOptions());

            json = json.Replace("save_key", "save-key");
            var policy = Base64Helper.Encode(json);

            return(policy);
        }
Example #11
0
        public void AddNoteTest()
        {
            string noteJson = System.IO.File.ReadAllText(@"E:\Project\JSON\note\getNoteContent.json");
            Note   note     = JsonSerializer.Deserialize <Note>(noteJson, MyJsonConvert.GetOptions());

            note.NoteId    = 2019;
            note.ContentId = 201901;
            NoteService.AddNote(note);

            // Assert.Fail();
        }
Example #12
0
        //获取用户信息

        public JsonResult Info(string token, [ModelBinder(BinderType = typeof(Hex2LongModelBinder))] long userId)
        {
            // long myUserId =MyConvert.HexToLong(userId);
            long myUserId = userId;

            if (myUserId != 0)
            {
                if (!AuthService.IsLogin(myUserId, token))
                {
                    ApiRe apiRe = new ApiRe()
                    {
                        Ok  = false,
                        Msg = "Not logged in",
                    };
                    return(Json(apiRe, MyJsonConvert.GetOptions()));
                }
                User user = UserService.GetUserByUserId(myUserId);

                if (user == null)
                {
                    ApiRe apiRe = new ApiRe()
                    {
                        Ok  = false,
                        Msg = "The user does not exist",
                    };
                    return(Json(apiRe, MyJsonConvert.GetOptions()));
                }
                else
                {
                    ApiUser apiUser = new ApiUser()
                    {
                        UserId   = user.UserId.ToString("x"),
                        Username = user.Username,
                        Email    = user.Email,
                        Logo     = user.Logo,
                        Verified = user.Verified
                    };
                    return(Json(apiUser, MyJsonConvert.GetOptions()));
                }
            }
            else
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Invalid user id",
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
        }
Example #13
0
        public IActionResult Note()
        {
            ViewBag.msg = LanguageResource.GetMsg();
            Dictionary <string, string> js = new Dictionary <string, string>();
            long userid = 1208692382644703232;

            Notebook[] noteBoooks = NotebookService.GetNoteBookTree(userid);
            string     json       = JsonSerializer.Serialize(noteBoooks, MyJsonConvert.GetOptions());

            //json  = System.IO.File.ReadAllText(@"E:\Project\JSON\notebook\GetNotebooks.json");
            js.Add("notebooks", json);
            ViewBag.js = js;
            return(View());
        }
        //todo:添加Tag
        public JsonResult AddTag(string token, string tag)
        {
            NoteTag noteTag = TagService.AddOrUpdateTag(getUserIdByToken(token), tag);

            if (noteTag == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = "添加标签失败"
                }, MyJsonConvert.GetOptions()));
            }
            else
            {
                return(Json(noteTag, MyJsonConvert.GetOptions()));
            }
        }
        //todo:获取同步的标签
        public JsonResult GetSyncTags(string token, int afterUsn, int maxEntry)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            NoteTag[] noteTags = TagService.GeSyncTags(user.UserId, afterUsn, maxEntry);
            return(Json(noteTags, MyJsonConvert.GetOptions()));
        }
Example #16
0
        public IActionResult getlist()
        {
            /**
             *  String json = "";
             * return Content(json);
             * */
            AppInfo[]    appInfos         = APPStoreInfoService.GetAPPList();
            APPStoreInfo aPPStoreInfoList = new APPStoreInfo()
            {
                resp_data = new Resp_Data()
                {
                    app_list = appInfos
                }
            };

            return(Json(aPPStoreInfoList, MyJsonConvert.GetOptions()));
        }
Example #17
0
        public void GetNoteContentTest()
        {
            string      a           = System.IO.File.ReadAllText(@"E:\github\MoreNote\MoreNote\TextFile.txt");
            NoteContent noteContent = NoteContentService.SelectNoteContent(123123);

            string json = JsonSerializer.Serialize(noteContent, MyJsonConvert.GetOptions());

            NoteContent noteContent2 = JsonSerializer.Deserialize <NoteContent>(json, MyJsonConvert.GetOptions());

            Console.WriteLine(noteContent2.UserId);
            Console.WriteLine(noteContent2.NoteId);
            Console.WriteLine(noteContent2.UpdatedUserId);
            //Console.WriteLine(noteContent2.Content);

            //string json=JsonConvert.SerializeObject(noteContent);
            //Console.WriteLine(json);
            // Assert.Fail();
        }
Example #18
0
        //添加notebook
        public IActionResult AddNotebook(string token, string title, string parentNotebookId, int seq)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                Notebook notebook = new Notebook()
                {
                    NotebookId       = SnowFlake_Net.GenerateSnowFlakeID(),
                    Title            = title,
                    Seq              = seq,
                    UserId           = user.UserId,
                    ParentNotebookId = MyConvert.HexToLong(parentNotebookId)
                };
                if (NotebookService.AddNotebook(ref notebook))
                {
                    ApiNotebook apiNotebook = fixNotebook(notebook);

                    return(Json(apiNotebook, MyJsonConvert.GetOptions()));
                }
                else
                {
                    ApiRe apiRe = new ApiRe()
                    {
                        Ok  = false,
                        Msg = "AddNotebook is error",
                    };

                    return(Json(apiRe, MyJsonConvert.GetOptions()));
                }
            }
        }
Example #19
0
        //获得同步状态
        //  [HttpPost]
        public JsonResult GetSyncState(string token)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };
                string json = JsonSerializer.Serialize(apiRe, MyJsonConvert.GetSimpleOptions());

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            ApiGetSyncState apiGetSyncState = new ApiGetSyncState()
            {
                LastSyncUsn  = user.Usn,
                LastSyncTime = UnixTimeHelper.GetTimeStampInLong(DateTime.Now)
            };

            return(Json(apiGetSyncState, MyJsonConvert.GetSimpleOptions()));
        }
Example #20
0
        //得到用户的所有笔记本
        public IActionResult GetNotebooks(string token)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                Notebook[]    notebooks    = NotebookService.GetAll(user.UserId);
                ApiNotebook[] apiNotebooks = fixNotebooks(notebooks);
                return(Json(apiNotebooks, MyJsonConvert.GetOptions()));
            }

            return(null);
        }
        //todo:删除trash
        public JsonResult DeleteTrash(string noteId, int usn, string token)
        {
            bool result = TrashService.DeleteTrashApi(MyConvert.HexToLong(noteId), getUserIdByToken(token), usn, out string msg, out int afterUsn);

            if (result)
            {
                return(Json(new ReUpdate()
                {
                    Ok = true,
                    Msg = "",
                    Usn = afterUsn
                }, MyJsonConvert.GetOptions()));
            }
            else
            {
                return(Json(new ReUpdate()
                {
                    Ok = false,
                    Msg = msg,
                    Usn = afterUsn
                }, MyJsonConvert.GetOptions()));
            }
        }
        //todo:删除标签
        public IActionResult DeleteTag(string token, string tag, int usn)
        {
            bool result = TagService.DeleteTagApi(getUserIdByToken(token), tag, usn, out int toUsn, out string msg);

            if (result)
            {
                ReUpdate reUpdate = new ReUpdate()
                {
                    Ok  = true,
                    Usn = toUsn,
                    Msg = msg
                };
                return(Json(reUpdate, MyJsonConvert.GetOptions()));
            }
            else
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = msg
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
        }
Example #23
0
        public void InsertNoteContentTest()
        {
            string      ContentJson = System.IO.File.ReadAllText(@"E:\Project\JSON\note\getNoteContent.json");
            NoteContent noteConteny = JsonSerializer.Deserialize <NoteContent>(ContentJson, MyJsonConvert.GetOptions());

            noteConteny.NoteId        = 201901;
            noteConteny.UpdatedUserId = SnowFlake_Net.GenerateSnowFlakeID();
            noteConteny.UserId        = SnowFlake_Net.GenerateSnowFlakeID();
            NoteContentService.InsertNoteContent(noteConteny);
        }
        //todo:更新笔记
        public JsonResult UpdateNote(ApiNote noteOrContent, string token)
        {
            Note noteUpdate     = new Note();
            var  needUpdateNote = false;
            var  re             = new ReUpdate();
            long tokenUserId    = getUserIdByToken(token);
            var  noteId         = MyConvert.HexToLong(noteOrContent.NoteId);

            //-------------校验参数合法性
            if (tokenUserId == 0)
            {
                re.Msg = "NOlogin";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }

            if (string.IsNullOrEmpty(noteOrContent.NoteId))
            {
                re.Msg = "noteIdNotExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }

            if (noteOrContent.Usn < 1)
            {
                re.Msg = "usnNotExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            // 先判断USN的问题, 因为很可能添加完附件后, 会有USN冲突, 这时附件就添错了
            var note        = NoteService.GetNote(noteId, tokenUserId);
            var noteContent = NoteContentService.GetNoteContent(note.NoteId, tokenUserId, false);

            if (note == null || note.NoteId == 0)
            {
                re.Msg = "notExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            //判断服务器版本与客户端版本是否一致
            if (note.Usn != noteOrContent.Usn)
            {
                re.Msg = "conflict";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            //-------------更新文件和附件内容
            if (noteOrContent.Files != null && noteOrContent.Files.Length > 0)
            {
                for (int i = 0; i < noteOrContent.Files.Length; i++)
                {
                    var file = noteOrContent.Files[i];
                    if (file.HasBody)
                    {
                        if (!string.IsNullOrEmpty(file.LocalFileId))
                        {
                            var result = upload("FileDatas[" + file.LocalFileId + "]", tokenUserId, noteId, file.IsAttach, out long serverFileId, out string msg);
                            if (!result)
                            {
                                if (string.IsNullOrEmpty(msg))
                                {
                                    re.Msg = "fileUploadError";
                                }
                                if (!string.Equals(msg, "notImage", System.StringComparison.OrdinalIgnoreCase))
                                {
                                    return(Json(re, MyJsonConvert.GetOptions()));
                                }
                            }
                            else
                            {
                                // 建立映射
                                file.FileId            = serverFileId.ToString("x");
                                noteOrContent.Files[i] = file;
                            }
                        }
                        else
                        {
                            return(Json(new ReUpdate()
                            {
                                Ok = false,
                                Msg = "LocalFileId_Is_NullOrEmpty",
                                Usn = 0
                            }, MyJsonConvert.GetSimpleOptions()));
                        }
                    }
                }
            }
            //更新用户元数据
            //int usn = UserService.IncrUsn(tokenUserId);

            // 移到外面来, 删除最后一个file时也要处理, 不然总删不掉
            // 附件问题, 根据Files, 有些要删除的, 只留下这些
            if (noteOrContent.Files != null)
            {
                AttachService.UpdateOrDeleteAttachApi(noteId, tokenUserId, noteOrContent.Files);
            }
            //-------------更新笔记内容
            var  afterContentUsn = 0;
            var  contentOk       = false;
            var  contentMsg      = "";
            long contentId       = 0;

            if (noteOrContent.Content != null)
            {
                // 把fileId替换下
                FixPostNotecontent(ref noteOrContent);
                // 如果传了Abstract就用之
                if (noteOrContent.Abstract != null)
                {
                    noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Abstract, 200);
                }
                else
                {
                    noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                }
            }
            else
            {
                noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteContent.Content, 200);
            }
            //上传noteContent的变更
            contentOk = NoteContentService.UpdateNoteContent(
                noteOrContent,
                out contentMsg,
                out contentId
                );
            //返回处理结果
            if (!contentOk)
            {
                re.Ok  = false;
                re.Msg = contentMsg;
                re.Usn = afterContentUsn;
                return(Json(re, MyJsonConvert.GetOptions()));
            }

            //-------------更新笔记元数据
            int afterNoteUsn = 0;
            var noteOk       = false;
            var noteMsg      = "";

            noteOk = NoteService.UpdateNote(
                ref noteOrContent,
                tokenUserId,
                contentId,
                true,
                true,
                out noteMsg,
                out afterNoteUsn
                );
            if (!noteOk)
            {
                re.Ok  = false;
                re.Msg = noteMsg;
                return(Json(re, MyJsonConvert.GetOptions()));
            }
            //处理结果
            //-------------API返回客户端信息
            note = NoteService.GetNote(noteId, tokenUserId);
            // noteOrContent.NoteId = noteId.ToString("x");
            // noteOrContent.UserId = tokenUserId.ToString("x");
            //  noteOrContent.Title = note.Title;
            // noteOrContent.Tags = note.Tags;
            // noteOrContent.IsMarkdown = note.IsMarkdown;
            // noteOrContent.IsBlog = note.IsBlog;
            //noteOrContent.IsTrash = note.IsTrash;
            //noteOrContent.IsDeleted = note.IsDeleted;
            //noteOrContent.IsTrash = note.IsTrash;

            //noteOrContent.Usn = note.Usn;
            //noteOrContent.CreatedTime = note.CreatedTime;
            //noteOrContent.UpdatedTime = note.UpdatedTime;
            //noteOrContent.PublicTime = note.PublicTime;

            noteOrContent.Content     = "";
            noteOrContent.Usn         = afterNoteUsn;
            noteOrContent.UpdatedTime = DateTime.Now;
            noteOrContent.IsDeleted   = false;
            noteOrContent.UserId      = tokenUserId.ToString("x");
            return(Json(noteOrContent, MyJsonConvert.GetOptions()));
        }
        //todo:添加笔记
        public JsonResult AddNote(ApiNote noteOrContent, string token)
        {
            var x = _accessor.HttpContext.Request.Form.Files;
            var z = x["FileDatas[5e36bafc26f2af1a79000000]"];
            //json 返回状态好乱呀 /(ㄒoㄒ)/~~
            Re   re          = Re.NewRe();
            long tokenUserId = getUserIdByToken(token);;
            long myUserId    = tokenUserId;

            if (noteOrContent == null || string.IsNullOrEmpty(noteOrContent.NotebookId))
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = "notebookIdNotExists"
                }, MyJsonConvert.GetSimpleOptions()));
            }
            long noteId = SnowFlake_Net.GenerateSnowFlakeID();


            if (noteOrContent.Title == null)
            {
                noteOrContent.Title = "无标题";
            }

            // TODO 先上传图片/附件, 如果不成功, 则返回false
            //-------------新增文件和附件内容
            int attachNum = 0;

            if (noteOrContent.Files != null && noteOrContent.Files.Length > 0)
            {
                for (int i = 0; i < noteOrContent.Files.Length; i++)
                {
                    var file = noteOrContent.Files[i];
                    if (file.HasBody)
                    {
                        if (!string.IsNullOrEmpty(file.LocalFileId))
                        {
                            var result = upload("FileDatas[" + file.LocalFileId + "]", tokenUserId, noteId, file.IsAttach, out long serverFileId, out string msg);
                            if (!result)
                            {
                                if (string.IsNullOrEmpty(msg))
                                {
                                    re.Msg = "fileUploadError";
                                }
                                else
                                {
                                    re.Msg = msg;
                                    return(Json(re, MyJsonConvert.GetOptions()));
                                }
                            }
                            else
                            {
                                // 建立映射
                                file.FileId            = serverFileId.ToString("x");
                                noteOrContent.Files[i] = file;
                                if (file.IsAttach)
                                {
                                    attachNum++;
                                }
                            }
                        }
                        else
                        {   //存在疑问
                            return(Json(new ReUpdate()
                            {
                                Ok = false,
                                Msg = "LocalFileId_Is_NullOrEmpty",
                                Usn = 0
                            }, MyJsonConvert.GetSimpleOptions()));
                        }
                    }
                }
            }
            else
            {
            }
            //-------------替换笔记内容中的文件ID
            FixPostNotecontent(ref noteOrContent);
            if (noteOrContent.Tags != null)
            {
                if (noteOrContent.Tags.Length > 0 && noteOrContent.Tags[0] == null)
                {
                    noteOrContent.Tags = Array.Empty <string>();
                    //noteOrContent.Tags= new string[] { ""};
                }
            }
            //-------------新增笔记对象
            Note note = new Note()
            {
                UserId        = tokenUserId,
                NoteId        = noteId,
                CreatedUserId = noteId,
                UpdatedUserId = noteId,
                NotebookId    = MyConvert.HexToLong(noteOrContent.NotebookId),
                Title         = noteOrContent.Title,
                Tags          = noteOrContent.Tags,
                Desc          = noteOrContent.Desc,
                IsBlog        = noteOrContent.IsBlog.GetValueOrDefault(),
                IsMarkdown    = noteOrContent.IsMarkdown.GetValueOrDefault(),
                AttachNum     = attachNum,
                CreatedTime   = noteOrContent.CreatedTime,
                UpdatedTime   = noteOrContent.UpdatedTime,
                ContentId     = SnowFlake_Net.GenerateSnowFlakeID()
            };

            //-------------新增笔记内容对象
            NoteContent noteContent = new NoteContent()
            {
                NoteContentId = note.ContentId,
                NoteId        = noteId,
                UserId        = tokenUserId,
                IsBlog        = note.IsBlog,
                Content       = noteOrContent.Content,
                Abstract      = noteOrContent.Abstract,
                CreatedTime   = noteOrContent.CreatedTime,
                UpdatedTime   = noteOrContent.UpdatedTime,
                IsHistory     = false
            };

            //-------------得到Desc, abstract
            if (string.IsNullOrEmpty(noteOrContent.Abstract))
            {
                if (noteOrContent.IsMarkdown.GetValueOrDefault())
                {
                    // note.Desc = MyHtmlHelper.SubMarkDownToRaw(noteOrContent.Content, 200);
                    noteContent.Abstract = MyHtmlHelper.SubMarkDownToRaw(noteOrContent.Content, 200);
                }
                else
                {
                    //note.Desc = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                    noteContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                }
            }
            else
            {
                note.Desc = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Abstract, 200);
            }
            if (noteOrContent.Desc == null)
            {
                if (noteOrContent.IsMarkdown.GetValueOrDefault())
                {
                    note.Desc = MyHtmlHelper.SubMarkDownToRaw(noteOrContent.Content, 200);
                }
                else
                {
                    note.Desc = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                }
            }
            else
            {
                note.Desc = noteOrContent.Desc;
            }

            note = NoteService.AddNoteAndContent(note, noteContent, myUserId);
            //-------------将笔记与笔记内容保存到数据库
            if (note == null || note.NoteId == 0)
            {
                return(Json(new ApiRe()
                {
                    Ok = false,
                    Msg = "AddNoteAndContent_is_error"
                }));
            }
            //-------------API返回客户端信息
            noteOrContent.NoteId      = noteId.ToString("x");
            noteOrContent.UserId      = tokenUserId.ToString("x");
            noteOrContent.Title       = note.Title;
            noteOrContent.Tags        = note.Tags;
            noteOrContent.IsMarkdown  = note.IsMarkdown;
            noteOrContent.IsBlog      = note.IsBlog;
            noteOrContent.IsTrash     = note.IsTrash;
            noteOrContent.IsDeleted   = note.IsDeleted;
            noteOrContent.IsTrash     = note.IsTrash;
            noteOrContent.IsTrash     = note.IsTrash;
            noteOrContent.Usn         = note.Usn;
            noteOrContent.CreatedTime = note.CreatedTime;
            noteOrContent.UpdatedTime = note.UpdatedTime;
            noteOrContent.PublicTime  = note.PublicTime;
            //Files = files

            //------------- 删除API中不需要返回的内容
            noteOrContent.Content  = "";
            noteOrContent.Abstract = "";
            //	apiNote := info.NoteToApiNote(note, noteOrContent.Files)

            return(Json(noteOrContent, MyJsonConvert.GetOptions()));
        }
Example #26
0
        public async Task <IActionResult> UpYunImageServiceHook()
        {
            var x = Request;

            using (var reader = new StreamReader(Request.Body))
            {
                var body = await reader.ReadToEndAsync();

                var message = JsonSerializer.Deserialize <ContentIdentifiesHookMessages>(body, MyJsonConvert.GetOptions());

                // Do something
            }

            return(Content("true"));
        }
Example #27
0
        public void ADDNoteBookTreeTest()
        {
            string          text      = System.IO.File.ReadAllText(@"E:\Project\JSON\GetNoteBookTree.json");
            List <Notebook> notebooks = JsonSerializer.Deserialize <List <Notebook> >(text, MyJsonConvert.GetOptions());

            foreach (Notebook n in notebooks)
            {
                Console.WriteLine(n.Title);
                InsertALL(n);
            }
            // Assert.Fail();
        }
        public string ToJsonString()
        {
            String json = JsonSerializer.Serialize(this, MyJsonConvert.GetOptions());

            return(json);
        }