[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult PictureDel(long id) { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); var PictureInfo = context.PictureInfo.Single(x => x.Id == id); var WordInfo = context.WordInfo.Where(x => x.PictureID == id); PictureInfo.Disable = true; foreach (var item in WordInfo) { item.Disable = true; } context.SaveChanges(); WordRedis.Del(); PictureRedis.Del(); return(Ok(new ApiResponse())); }
[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult WordsUpLoad(WordDto body) { string token = _httpContext.HttpContext.Request.Headers["Authorization"]; AuthRedis.GetUserByToken(token, out UserInfo userInfo); using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); if (body.Eid == null) { int count = context.WordInfo.Where(x => x.PictureID == body.id).Count(); if (count > 0) { return(Ok(new ApiResponse(code: CodeAndMessage.已存在对应的资讯文档))); } WordInfo WordInfos = new WordInfo() { Id = SequenceID.GetSequenceID(), CreateTime = DateTime.Now, Disable = false, HtmlContent = body.HtmlContent, PictureID = body.id, LastModifiedTime = DateTime.Now, HtmlExplain = body.HtmlExplain, HtmlTitle = body.HtmlTitle, AttachedPath = body.AttachedPath }; context.Add(WordInfos); context.SaveChanges(); WordRedis.Del(); } else { var WordInfo = context.WordInfo.Single(x => x.Id == body.Eid); WordInfo.LastModifiedTime = DateTime.Now; WordInfo.HtmlContent = body.HtmlContent; WordInfo.HtmlExplain = body.HtmlExplain; WordInfo.HtmlTitle = body.HtmlTitle; WordInfo.AttachedPath = body.AttachedPath; context.SaveChanges(); WordRedis.Del(); } return(Ok(new ApiResponse())); }
[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult WordInfo(WordSelectDto body) { int total = 0; List <WordListDto> wordListDtos = new List <WordListDto>(); if (!WordRedis.GetAll(out List <WordInfo> Word)) { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); Word = context.WordInfo.Where(x => x.Disable == false).Include(x => x.PictureInfos).Include(x => x.PictureInfos.Users).ToList(); total = Word.Count(); if (Word != null && Word.Count > 0) { WordRedis.SaveAll(Word); } if (body.StartTime != null) { Word = Word.Where(x => x.CreateTime >= body.StartTime).ToList(); } if (body.EndTime != null) { Word = Word.Where(x => x.CreateTime <= body.EndTime).ToList(); } Word = Word.OrderByDescending(x => x.CreateTime).Skip(body.pageSize * (body.pageNum - 1)).Take(body.pageSize).ToList(); foreach (var item in Word) { WordListDto WordInfos = new WordListDto() { ID = item.Id, CreateTime = item.CreateTime, HtmlContent = item.HtmlContent, HtmlExplain = item.HtmlExplain, UserName = item.PictureInfos.Users.UserName, HtmlTitle = item.HtmlTitle, PictureTitle = item.PictureInfos.PictureTitle }; wordListDtos.Add(WordInfos); } return(Ok(new ApiResponse(wordListDtos, total))); } else { total = Word.Count(); Word = Word.OrderByDescending(x => x.CreateTime).Skip(body.pageSize * (body.pageNum - 1)).Take(body.pageSize).ToList(); foreach (var item in Word) { WordListDto WordInfos = new WordListDto() { ID = item.Id, CreateTime = item.CreateTime, HtmlContent = item.HtmlContent, HtmlExplain = item.HtmlExplain, UserName = item.PictureInfos.Users.UserName, HtmlTitle = item.HtmlTitle, PictureTitle = item.PictureInfos.PictureTitle }; wordListDtos.Add(WordInfos); } return(Ok(new ApiResponse(wordListDtos, total))); } }