Exemple #1
0
        // note与apiNote的转换
        public static ApiNote ToApiNote(ref Note note, APINoteFile[] files)
        {
            ApiNote apiNote = new ApiNote()
            {
                NoteId     = note.NoteId.ToString("x"),
                NotebookId = note.NotebookId.ToString("x"),
                UserId     = note.UserId.ToString("x"),
                Title      = note.Title,
                Desc       = note.Desc,
                Tags       = note.Tags,


                IsMarkdown  = note.IsMarkdown,
                IsBlog      = note.IsBlog,
                IsTrash     = note.IsTrash,
                IsDeleted   = note.IsDeleted,
                Usn         = note.Usn,
                CreatedTime = note.CreatedTime,
                UpdatedTime = note.UpdatedTime,
                PublicTime  = note.PublicTime,
                Files       = (files == null?Array.Empty <APINoteFile>() :files)
            };

            return(apiNote);
        }
Exemple #2
0
        // note与apiNote的转换
        public static ApiNote[] ToApiNotes(Note[] notes)
        {
            // 2, 得到所有图片, 附件信息
            // 查images表, attachs表

            if (notes != null && notes.Length > 0)
            {
                ApiNote[] apiNotes = new ApiNote[notes.Length];
                //得到所有文件

                long[] noteIds = new long[notes.Length];
                for (int i = 0; i < notes.Length; i++)
                {
                    noteIds[i] = notes[i].NoteId;
                }


                Dictionary <long, List <APINoteFile> > noteFilesMap = getFiles(noteIds);
                for (int i = 0; i < notes.Length; i++)
                {
                    APINoteFile[] aPINoteFiles = noteFilesMap.ContainsKey(notes[i].NoteId)? noteFilesMap[notes[i].NoteId].ToArray():null;
                    apiNotes[i] = ToApiNote(ref notes[i], aPINoteFiles);
                }

                return(apiNotes);
            }
            else
            {
                return(new ApiNote[0]);
            }
        }
        //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()));
            }
        }
Exemple #4
0
        public IActionResult GetNoteAndContent(string token, string noteId)
        {
            User tokenUser = tokenSerivce.GetUserByToken(token);

            if (tokenUser == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ""
                }, MyJsonConvert.GetLeanoteOptions()));
            }
            try
            {
                NoteAndContent noteAndContent = noteService.GetNoteAndContent(noteId.ToLongByHex(), 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.GetLeanoteOptions()));
                }
                else
                {
                    return(Json(apiNote, MyJsonConvert.GetLeanoteOptions()));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ex.Message
                }, MyJsonConvert.GetLeanoteOptions()));
            }
        }
Exemple #5
0
 public void FixPostNotecontent(ref ApiNote noteOrContent)
 {
     //todo 这里需要完成fixPostNotecontent
     if (noteOrContent == null || string.IsNullOrEmpty(noteOrContent.Content))
     {
         return;
     }
     APINoteFile[] files = noteOrContent.Files;
     if (files != null && files.Length > 0)
     {
         foreach (var file in files)
         {
             if (file.FileId != null && file.LocalFileId != null)
             {
                 if (!file.IsAttach)
                 {
                     //处理图片链接
                     Regex regex = new Regex(@"(https*://[^/]*?/api/file/getImage\?fileId=)" + file.LocalFileId);
                     if (regex.IsMatch(noteOrContent.Content))
                     {
                         noteOrContent.Content = regex.Replace(noteOrContent.Content, "${1}" + file.FileId);
                     }
                 }
                 else
                 {
                     //处理附件链接
                     Regex regex = new Regex(@"(https*://[^/]*?/api/file/getAttach\?fileId=)" + file.LocalFileId);
                     if (regex.IsMatch(noteOrContent.Content))
                     {
                         noteOrContent.Content = regex.Replace(noteOrContent.Content, "${1}" + file.FileId);
                     }
                 }
             }
         }
     }
 }
Exemple #6
0
        public static void CreateLinks(this ApiNote note, ActionContext context, LinkGenerator linkGen)
        {
            if (context == null || linkGen == null)
            {
                return;
            }

            var links = new List <Link>
            {
                // self
                new()
                {
                    Title  = "self",
                    Rel    = "self",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, "GetNoteById", new { id = note.Id }),
                    Method = "Get"
                },
                new()
                {
                    Title  = "AddNote",
                    Rel    = "create_note",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, "AddNote", null),
                    Method = "POST"
                },
                new()
                {
                    Title  = "UpdateNote",
                    Rel    = "update_note",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, "UpdateNote", new { id = note.Id }),
                    Method = "PUT"
                },
                new()
                {
                    Title  = "PatchNote",
                    Rel    = "patch_note",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, "PatchNote", new { id = note.Id }),
                    Method = "PATCH"
                }
            };

            // child
            var authorId = note.AuthorId;

            if (authorId != Guid.Empty)
            {
                links.Add(
                    new Link
                {
                    Title  = "Author",
                    Rel    = "get_author",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, "GetAuthorById", new { id = authorId }),
                    Method = "Get"
                });
            }

            var catalogId = note.CatalogId;

            if (catalogId > 0)
            {
                links.Add(
                    new Link
                {
                    Title  = "NoteCatalog",
                    Rel    = "get_noteCatalog",
                    Href   = linkGen.GetUriByRouteValues(context.HttpContext, "GetNoteCatalogById", new { id = catalogId }),
                    Method = "Get"
                });
            }

            note.Links = links;
        }
Exemple #7
0
        public JsonResult UpdateNote(ApiNote noteOrContent, string token)
        {
            Note noteUpdate     = new Note();
            var  needUpdateNote = false;
            var  re             = new ReUpdate();
            long?tokenUserId    = GetUserIdByToken(token);
            var  noteId         = noteOrContent.NoteId.ToLongByHex();

            //-------------校验参数合法性
            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 = UploadImages("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.GetLeanoteOptions()));
                                }
                            }
                            else
                            {
                                // 建立映射
                                file.FileId            = serverFileId.ToHex24();
                                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.UpdateOrDeleteAttachApiAsync(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.GetLeanoteOptions()));
            }

            //-------------更新笔记元数据
            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.GetLeanoteOptions()));
            }
            //处理结果
            //-------------API返回客户端信息
            note = noteService.GetNote(noteId, tokenUserId);
            // noteOrContent.NoteId = noteId.ToHex24();
            // noteOrContent.UserId = tokenUserId.ToHex24();
            //  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.ToHex24();
            return(Json(noteOrContent, MyJsonConvert.GetLeanoteOptions()));
        }
Exemple #8
0
        public async Task <IActionResult> AddNote(ApiNote noteOrContent, string token)
        {
            var re = new ApiRe();

            var user = tokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                return(LeanoteJson(re));
            }

            //json 返回状态乱

            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 = idGenerator.NextId();

            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 = UploadImages("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.GetLeanoteOptions()));
                                }
                            }
                            else
                            {
                                // 建立映射
                                file.FileId            = serverFileId.ToHex24();
                                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 = tokenUserId,
                UpdatedUserId = noteId,
                NotebookId    = noteOrContent.NotebookId.ToLongByHex(),
                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     = idGenerator.NextId()
            };

            //-------------新增笔记内容对象
            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.ToHex24();
            noteOrContent.UserId      = tokenUserId.ToHex24();
            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.GetLeanoteOptions()));
        }
        public static bool UpdateNoteContent(ApiNote apiNote,
                                             out string msg, out long contentId)
        {
            using (var db = new DataContext())
            {
                //更新 将其他笔记刷新
                var noteId      = MyConvert.HexToLong(apiNote.NoteId);
                var note        = db.Note.Where(b => b.NoteId == noteId).First();
                var noteContent = db.NoteContent.Where(b => b.NoteId == noteId && b.IsHistory == false).FirstOrDefault();
                //如果笔记内容发生变化,生成新的笔记内容
                if (apiNote.Content != null)
                {
                    //新增笔记内容,需要将上一个笔记设置为历史笔记
                    db.NoteContent.Where(b => b.NoteId == noteId && b.IsHistory == false).Update(x => new NoteContent()
                    {
                        IsHistory = true
                    });
                    contentId = SnowFlake_Net.GenerateSnowFlakeID();
                    NoteContent contentNew = new NoteContent()
                    {
                        NoteContentId = contentId,
                        NoteId        = noteContent.NoteId,
                        UserId        = noteContent.UserId,
                        IsBlog        = noteContent.IsBlog,
                        Content       = noteContent.Content,
                        Abstract      = noteContent.Abstract,
                        CreatedTime   = noteContent.CreatedTime,
                        UpdatedTime   = noteContent.UpdatedTime,
                        UpdatedUserId = noteContent.UpdatedUserId,
                        IsHistory     = noteContent.IsHistory,
                    };
                    contentNew.IsHistory = false;
                    if (apiNote.IsBlog != null)
                    {
                        contentNew.IsBlog = apiNote.IsBlog.GetValueOrDefault();
                    }
                    if (apiNote.Abstract != null)
                    {
                        contentNew.Abstract = apiNote.Abstract;
                    }
                    if (apiNote.Content != null)
                    {
                        contentNew.Content = apiNote.Content;
                    }
                    if (apiNote.UpdatedTime != null)
                    {
                        contentNew.UpdatedTime = apiNote.UpdatedTime;
                    }
                    db.NoteContent.Add(contentNew);
                    msg = "";
                    return(db.SaveChanges() > 0);
                }
                else
                {   //没有新增笔记内容,那么仅仅修改原始笔记内容就可以了
                    contentId = noteContent.NoteContentId;
                    if (apiNote.IsBlog != null)
                    {
                        noteContent.IsBlog = apiNote.IsBlog.GetValueOrDefault();
                    }
                    if (apiNote.Abstract != null)
                    {
                        noteContent.Abstract = apiNote.Abstract;
                    }

                    if (apiNote.UpdatedTime != null)
                    {
                        noteContent.UpdatedTime = apiNote.UpdatedTime;
                    }
                }
                msg = "";
                db.SaveChanges();
                return(true);
            }
        }
Exemple #10
0
        private void button2_Click(object sender, EventArgs e)
        {
            XmlData xd = new XmlData();
            xd.ArrayOfApiNote = new List<ApiNote>();
            xd.ApiNote = new ApiNote();
            //xd.ApiNote.NoteCode = null;
            xd.ApiNote.NoteMsg = null;

            //Testa testa = new Testa();
            //testa.a = "a";
            //testa.AddTime = UnDate.shortNowTime();
            //testa.b = null;
            //testa.c = "c";
            //testa.d = "d";
            //testa.e = "e";
            //testa.f = "f";

            //xd.Test = testa;
            //xd.Testa = new Testa();
            //xd.ApiBase = new ApiBase()
            //{
            //    IsTest = "dd",
            //    Model = "md",
            //    Method = "me",
            //    guid = null
            //};
            //xd.ApiBase.ArrayOfTest = new List<Test>();
            ApiNote note = new ApiNote();
            note.NoteCode = 1;
            note.NoteMsg = "ddd";

            ApiNote note1 = new ApiNote();
            note1.NoteCode = 2;
            note1.NoteMsg = "eeee";

            xd.ArrayOfApiNote.Add(note);
            xd.ArrayOfApiNote.Add(note1);

            //xd.ArrayOfApiNote = null;
            //xd.ApiBase = null;

            //string s = UnStrReg.regPartEmail.Replace("*****@*****.**", "$1***$2");

            string s = UnXMMPXml.tToXml(typeof(XmlData), xd);
            //s = @"<XmlData><ApiNote><NoteCode>1</NoteCode><NoteMsg>OK:查询成功</NoteMsg></ApiNote><Cards><CardsID>52923</CardsID><CardsUID>2016102810551249399747415</CardsUID><CardsGUID>01a7145c-b7b1-44de-9fa0-24002c0bc352</CardsGUID><CardsChipNo>0008281529</CardsChipNo><CardsNumber>0008281529</CardsNumber><AddTime>2016-10-28 10:54:56</AddTime><AddTimeStamp>1477623296567</AddTimeStamp><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CardCreateRecordGUID>0fffe23a-ac7d-4747-981b-af7bbc2b24da</CardCreateRecordGUID><MemberInfoGUID>f138cb98-7146-46b8-868b-15a131f59a44</MemberInfoGUID><Balance>1468.2600</Balance><Balance1>978.7308</Balance1><Balance2>489.5292</Balance2><EffectTime>2016-10-28 00:00:00</EffectTime><EffectTimeStamp>1477584000000</EffectTimeStamp><InvalidTime>2016-10-27</InvalidTime><InvalidTimeStamp>1477929600000</InvalidTimeStamp><CardType p3:type=""CardTypeExt"" xmlns:p3=""http://www.w3.org/2001/XMLSchema-instance"" ><CardTypeID>67</CardTypeID><CardTypeUID>20161027184835394</CardTypeUID><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CreateNum>1</CreateNum><CardTypeName>过期过期27</CardTypeName><NeedBind>1</NeedBind><IsPhysical>1</IsPhysical><FaceValue>1500.0000</FaceValue><Price>1000.0000</Price><FlatCost>12.0000</FlatCost><RechargeType>0</RechargeType><PaymentCiscount>0.5000</PaymentCiscount><IsPaymentCiscount>1</IsPaymentCiscount><RightsCiscount>0.2000</RightsCiscount><IsRightsCiscount>1</IsRightsCiscount><EffectTimeStamp>0</EffectTimeStamp><InvalidTime>2016-10-27</InvalidTime><InvalidTimeStamp>1477929600000</InvalidTimeStamp><EffectDuration>0</EffectDuration><InvalidDuration>0</InvalidDuration><ArrayOfViewCardTypeBindStore><ViewCardTypeBindStore><CardTypeBindStoreID>780</CardTypeBindStoreID><CardTypeBindStoreUID>20161027184835398</CardTypeBindStoreUID><CardTypeBindStoreGUID>273b17db-e039-4011-9224-14b29814e9fa</CardTypeBindStoreGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><StoreGUID>59914f92-72e6-4935-8f71-921eb11bbea2</StoreGUID><ViewCardTypeBindStoreID>780</ViewCardTypeBindStoreID><Name>高升</Name><Address>四川省成都市武侯区</Address></ViewCardTypeBindStore><ViewCardTypeBindStore><CardTypeBindStoreID>781</CardTypeBindStoreID><CardTypeBindStoreUID>20161027184835400</CardTypeBindStoreUID><CardTypeBindStoreGUID>e9853606-8a76-455b-afcc-5f68cbb8783f</CardTypeBindStoreGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><StoreGUID>0bc8d932-1ae7-49bf-86c8-06bdc2c98e80</StoreGUID><ViewCardTypeBindStoreID>781</ViewCardTypeBindStoreID><Name>丽都店</Name><Address>四川省成都市龙泉驿区</Address></ViewCardTypeBindStore><ViewCardTypeBindStore><CardTypeBindStoreID>784</CardTypeBindStoreID><CardTypeBindStoreUID>20161027184835406</CardTypeBindStoreUID><CardTypeBindStoreGUID>77528182-f299-49f3-95dd-7389b47dfeb3</CardTypeBindStoreGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><StoreGUID>7b664309-2fc5-4fa4-b0ce-ad6dd9a74779</StoreGUID><ViewCardTypeBindStoreID>784</ViewCardTypeBindStoreID><Name>的萨达但是爱的</Name><Address>四川省广安市</Address></ViewCardTypeBindStore><ViewCardTypeBindStore><CardTypeBindStoreID>783</CardTypeBindStoreID><CardTypeBindStoreUID>20161027184835404</CardTypeBindStoreUID><CardTypeBindStoreGUID>38ffdd1f-6d34-4a50-8806-ad46e4a9b5ca</CardTypeBindStoreGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><StoreGUID>708ce206-9679-40aa-933c-44878211383b</StoreGUID><ViewCardTypeBindStoreID>783</ViewCardTypeBindStoreID><Name>北门店</Name><Address>四川省</Address></ViewCardTypeBindStore><ViewCardTypeBindStore><CardTypeBindStoreID>782</CardTypeBindStoreID><CardTypeBindStoreUID>20161027184835402</CardTypeBindStoreUID><CardTypeBindStoreGUID>2a64d9af-8d57-4e7b-b36b-b57dd2107ce8</CardTypeBindStoreGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><StoreGUID>caab4c9d-6169-4803-873a-467b89d81d28</StoreGUID><ViewCardTypeBindStoreID>782</ViewCardTypeBindStoreID><Name>华阳店</Name><Address>四川省成都市龙泉驿区</Address></ViewCardTypeBindStore></ArrayOfViewCardTypeBindStore><ArrayOfCardRechargeLadder /><IsExpire>0</IsExpire><Status>1</Status><EnteringStatus>1</EnteringStatus></CardType><MemberInfo><MemberInfoID>1088820</MemberInfoID><MemberInfoUID>20161027105913619</MemberInfoUID><MemberInfoGUID>f138cb98-7146-46b8-868b-15a131f59a44</MemberInfoGUID><IsDelete>0</IsDelete><RegTel>18811772985</RegTel><RegDevice>0</RegDevice><TradingPassWord>2466d6104a1e79065f16fc1b3b3564ff</TradingPassWord><RegDateTime>2016-10-27 10:59:13</RegDateTime><RegDateTimeStamp>1477537153322</RegDateTimeStamp><NickName>aaa</NickName><BrithdayStamp p4:nil=""true"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"" /><Sex>0</Sex><CitysGUID p4:nil=""true"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"" /></MemberInfo><StoreGUID>59914f92-72e6-4935-8f71-921eb11bbea2</StoreGUID></Cards><CardStock><CardStockID>600087</CardStockID><CardStockUID>20161027184913450</CardStockUID><CardStockGUID>dd54447f-4146-44a5-8c33-d202532eb434</CardStockGUID><CardsChipNo>0008281529</CardsChipNo><CardsNumber>0008281529</CardsNumber><CardStockType>1</CardStockType><CardStockState>1</CardStockState><AddTime>2016-10-27 18:49:13</AddTime><AddTimeStamp>1477565353829</AddTimeStamp><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><CardType><CardTypeID>67</CardTypeID><CardTypeUID>20161027184835394</CardTypeUID><CardTypeGUID>297e99fa-ff1e-4544-8ba0-a618c41a33d4</CardTypeGUID><IsDelete>0</IsDelete><IsEnable>1</IsEnable><CreateNum>1</CreateNum><CardTypeName>过期过期27</CardTypeName><NeedBind>1</NeedBind><IsPhysical>1</IsPhysical><FaceValue>1500.0000</FaceValue><Price>1000.0000</Price><FlatCost>12.0000</FlatCost><RechargeType>0</RechargeType><PaymentCiscount>0.5000</PaymentCiscount><IsPaymentCiscount>1</IsPaymentCiscount><RightsCiscount>0.2000</RightsCiscount><IsRightsCiscount>1</IsRightsCiscount><EffectTimeStamp>0</EffectTimeStamp><InvalidTime>2016-10-27</InvalidTime><InvalidTimeStamp>1477929600000</InvalidTimeStamp><EffectDuration>0</EffectDuration><InvalidDuration>0</InvalidDuration></CardType></CardStock><GeneralMsg><IsAvailable>1</IsAvailable><Msg /></GeneralMsg></XmlData>";
            //XmlData inxd = (XmlData)UnXMMPXml.xmlToT(typeof(XmlData),s);
            //Console.WriteLine(inxd.ApiNote.NoteCode + "//");
            //Console.WriteLine(inxd.Test.a + "//");
            //Console.WriteLine(inxd.ArrayOfApiNote[0].NoteMsg + "//");
            //string s = @"<Test p2:type='Testa' xmlns:p2='http://www.w3.org/2001/XMLSchema-instance'><e>e</e><f>f</f><a>a</a><b p2:nil='true' /><c>c</c><d>d</d><AddTime>2016-10-31 10:21:01</AddTime></Test>";

            //var doc = UnXMMPHelp.Json2Xml(s);
            //s = UnXMMPXml.tToXml(typeof(XmlData), doc);
            Console.WriteLine(s);
            //UnXMMPXml.removeXmlNotes(ref s);
            UnXMMPXml.removeNil(ref s);
            Console.WriteLine(s);
        }
Exemple #11
0
        public bool UpdateNoteContent(ApiNote apiNote, out string msg, out long?contentId)
        {
            //更新 将其他笔记刷新
            var noteId      = apiNote.NoteId.ToLongByHex();
            var note        = dataContext.Note.Where(b => b.NoteId == noteId).First();
            var noteContent = dataContext.NoteContent.Where(b => b.NoteId == noteId && b.IsHistory == false).FirstOrDefault();

            //如果笔记内容发生变化,生成新的笔记内容
            if (apiNote.Content != null)
            {
                //新增笔记内容,需要将上一个笔记设置为历史笔记
                dataContext.NoteContent.Where(b => b.NoteId == noteId && b.IsHistory == false).Update(x => new NoteContent()
                {
                    IsHistory = true
                });
                contentId = idGenerator.NextId();
                NoteContent contentNew = new NoteContent()
                {
                    NoteContentId = contentId,
                    NoteId        = noteContent.NoteId,
                    UserId        = noteContent.UserId,
                    IsBlog        = noteContent.IsBlog,
                    Content       = noteContent.Content,
                    Abstract      = noteContent.Abstract,
                    CreatedTime   = noteContent.CreatedTime,
                    UpdatedTime   = noteContent.UpdatedTime,
                    UpdatedUserId = noteContent.UpdatedUserId,
                    IsHistory     = noteContent.IsHistory,
                };
                contentNew.IsHistory = false;

                if (apiNote.IsBlog != null)
                {
                    contentNew.IsBlog = apiNote.IsBlog.GetValueOrDefault();
                }
                if (apiNote.Abstract != null)
                {
                    contentNew.Abstract = apiNote.Abstract;
                }
                if (apiNote.Content != null)
                {
                    contentNew.Content = apiNote.Content;
                }
                if (apiNote.UpdatedTime != null)
                {
                    contentNew.UpdatedTime = apiNote.UpdatedTime;
                }
                UpdataVector(ref contentNew);
                dataContext.NoteContent.Add(contentNew);
                msg = "";
                return(dataContext.SaveChanges() > 0);
            }
            else
            {   //没有新增笔记内容,那么仅仅修改原始笔记内容就可以了
                contentId = noteContent.NoteContentId;
                if (apiNote.IsBlog != null)
                {
                    noteContent.IsBlog = apiNote.IsBlog.GetValueOrDefault();
                }
                if (apiNote.Abstract != null)
                {
                    noteContent.Abstract = apiNote.Abstract;
                }

                if (apiNote.UpdatedTime != null)
                {
                    noteContent.UpdatedTime = apiNote.UpdatedTime;
                }
            }
            msg = "";
            dataContext.SaveChanges();
            return(true);
        }
Exemple #12
0
        /// <summary>
        /// 更新笔记 元数据
        /// </summary>
        /// <param name="apiNote"></param>
        /// <returns></returns>
        public static bool UpdateNote(ref ApiNote apiNote, long updateUser, long contentId, bool verifyUsn, bool verifyOwner,
                                      out string msg, out int afterUsn)
        {
            var noteId = MyConvert.HexToLong(apiNote.NoteId);

            afterUsn = 0;
            if (apiNote == null)
            {
                msg = "apiNote_is_null";
                return(false);
            }
            // var noteId = MyConvert.HexToLong(apiNote.NoteId);
            if (noteId == 0)
            {
                msg = "noteId_is_note_long_Number";
                return(false);
            }
            using (var db = new DataContext())
            {
                var result = db.Note.Where(b => b.NoteId == noteId && b.UserId == updateUser);
                if (result == null)
                {
                    msg = "inexistence";
                    return(false);
                }
                var note = result.FirstOrDefault();

                if (verifyUsn)
                {
                    if (note.Usn != apiNote.Usn)
                    {
                        msg = "Verify_Usn_Failure";
                        return(false);
                    }
                }
                if (verifyOwner)
                {
                    if (note.UserId != updateUser)
                    {
                        msg = "Verify_updateUser_Failure";
                        return(false);
                    }
                }
                if (apiNote.Desc != null)
                {
                    note.Desc = apiNote.Desc;
                }

                if (apiNote.Title != null)
                {
                    note.Title = apiNote.Title;
                }
                if (apiNote.IsTrash != null)
                {
                    note.IsTrash = apiNote.IsTrash.GetValueOrDefault();
                }
                if (apiNote.IsBlog != null)
                {
                    if (note.IsBlog == false && apiNote.IsBlog == true)
                    {
                        note.PublicTime = DateTime.Now;
                    }
                    note.IsBlog = apiNote.IsBlog.GetValueOrDefault(false);
                }
                if (apiNote.Tags != null)
                {
                    note.Tags = apiNote.Tags;
                    TagService.AddTags(note.UserId, note.Tags);
                    BlogService.ReCountBlogTags(note.UserId);
                }
                if (apiNote.NotebookId != null)
                {
                    var noteBookId = MyConvert.HexToLong(apiNote.NotebookId);
                    if (note.NotebookId == 0)
                    {
                        msg = "NotebookId_Is_Illegal";
                        return(false);
                    }
                    if (note.NotebookId != noteBookId)
                    {
                        // 如果修改了notebookId, 则更新notebookId'count
                        // 两方的notebook也要修改
                        NotebookService.ReCountNotebookNumberNotes(note.NotebookId);
                        NotebookService.ReCountNotebookNumberNotes(noteBookId);
                        note.NotebookId = noteBookId;
                    }
                }
                if (apiNote.Content != null)
                {
                    note.ContentId = contentId;
                    if (apiNote.Abstract == null)
                    {
                        if (apiNote.IsMarkdown.GetValueOrDefault(note.IsMarkdown))
                        {
                            note.Desc = MyHtmlHelper.SubMarkDownToRaw(apiNote.Content, 200);
                        }
                        else
                        {
                            note.Desc = MyHtmlHelper.SubHTMLToRaw(apiNote.Content, 200);
                        }
                        //  note.Desc = MyHtmlHelper.SubStringHTMLToRaw(apiNote.Content, 200);
                    }
                    else
                    {
                        note.Desc = MyHtmlHelper.SubHTMLToRaw(apiNote.Abstract, 200);
                        //note.Desc = MyHtmlHelper.SubStringHTMLToRaw(apiNote.Abstract, 200);
                    }
                }
                if (apiNote.UpdatedTime != null)
                {
                    note.UpdatedTime = Tools.FixUrlTime(apiNote.UpdatedTime);
                }
                else
                {
                    note.UpdatedTime = DateTime.Now;
                }
                if (note.IsBlog && note.HasSelfDefined)
                {
                    note.ImgSrc = null;
                    note.Desc   = null;
                }
                if (apiNote.IsTrash != null)
                {
                    note.IsTrash = apiNote.IsTrash.GetValueOrDefault(false);
                    NotebookService.ReCountNotebookNumberNotes(note.NotebookId);
                }
                if (apiNote.IsMarkdown != null)
                {
                    note.IsMarkdown = apiNote.IsMarkdown.GetValueOrDefault();
                }
                note.UpdatedUserId = MyConvert.HexToLong(apiNote.UserId);
                //更新用户元数据乐观锁
                afterUsn = UserService.IncrUsn(note.UserId);
                //更新笔记元数据乐观锁
                note.Usn = afterUsn;
                db.SaveChanges();
                msg = "success";
                return(true);
            }
        }