/// <summary> /// 获取笔记 /// </summary> /// <param name="currentUser"></param> /// <param name="request">Note</param> /// <returns>Note</returns> public Response Execute(User currentUser, string request) { var req = JsonConvert.DeserializeObject <Request <Note> >(request); var cmd = CommandHelper.CreateProcedure <Note>(text: "sp_GetNote"); cmd.Params.Add("@noteId", req.Filter.Id); cmd.Params.Add("@userId", currentUser.Id); var result = DbContext.GetInstance().Execute(cmd); var note = result.FirstEntity <Note>(); if (note == null) { return(ResultHelper.Fail(ErrorCode.DATA_NOTEXIST, "未找到此精彩瞬间")); } note.TryGetFiles(); var support = NoteHelper.GetNoteSupportList(note.Id.ToString()); note.SupportList = support.Entities.ToList <EntityBase, NoteSupport>(); note.SupportCount = support.RowCount; if (!string.IsNullOrEmpty(note.CourseId)) { note.CourseSummary = NoteHelper.GetCourseSummary(note.CourseId); } return(result); }
public Response Execute(User currentUser, string request) { var req = JsonConvert.DeserializeObject <Request <GetNoteListFilter> >(request); _currentUser = currentUser; var cmd = CommandHelper.CreateProcedure <Note>(text: "sp_GetNoteList"); if (currentUser.Id == req.Filter.UserId) { cmd.Params.Add("@isSelf", true);//查询自己的笔记 (自己笔记首页) } else { cmd.Params.Add("@isSelf", false);//查询别人的笔记 (笔记首页所有人的) } cmd.Params.Add("@userId", currentUser.Id); cmd.Params.Add("@noteCreatorId", req.Filter.UserId); cmd.Params.Add("@isAll", req.Filter.IsAll); //true查询所有人 false 查询某个人 cmd.CreateParamPager(req.Filter); var result = DbContext.GetInstance().Execute(cmd); result.SetRowCount(); var noteList = result.Entities.ToList <EntityBase, Note>(); List <Note> resultNoteList = new List <Note>(); foreach (var item in noteList) { //获取笔记图片 item.TryGetFiles(); //获取笔记分享的课程摘要(如果有) if (!string.IsNullOrEmpty(item.CourseId)) { item.CourseSummary = NoteHelper.GetCourseSummary(item.CourseId); } if (!string.IsNullOrEmpty(item.Content)) { resultNoteList.Add(item); } } //过滤当前用户隐藏的笔记和 笔记创建人 resultNoteList = FilterNoteListByCurrentUser(resultNoteList); result.Entities = resultNoteList.ToList <Note, EntityBase>(); return(result); }